0% found this document useful (0 votes)
16 views6 pages

BaiTapGoiHamVaThuTuc

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

BaiTapGoiHamVaThuTuc

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Source code SQL Server:

USE [Student]

GO

/****** Object: Table [dbo].[Student] Script Date: 02/10/2024 08:43:30 PM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Student](

[id] [int] NOT NULL,

[student_name] [nvarchar](100) NULL,

[gender] [nvarchar](50) NULL,

PRIMARY KEY CLUSTERED

[id] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,


ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON
[PRIMARY]

) ON [PRIMARY]

GO

/****** Object: UserDefinedFunction [dbo].[f_female_student] Script Date: 02/10/2024 08:43:30


PM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

Create function [dbo].[f_female_student]()

returns table

as

return (SELECT *

FROM Student
WHERE Student.gender like '%female%')

GO

/****** Object: StoredProcedure [dbo].[get_male_student] Script Date: 02/10/2024 08:43:30 PM


******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

Create proc [dbo].[get_male_student]

as

begin

SELECT * FROM Student WHERE Student.gender = 'male'

end

GO

Soure code form:


public partial class Form1 : Form

MyDB db = new MyDB();

public Form1()

InitializeComponent();

loadData();

void loadData()

string query = "SELECT * FROM Student";

db.openConnection();

SqlCommand cmd = new SqlCommand(query, db.getConnection);

SqlDataAdapter adapter = new SqlDataAdapter(cmd);


DataTable dt = new DataTable();

adapter.Fill(dt);

dgv_information.DataSource = dt;

db.closeConnection();

private void btn_selectMale_Click(object sender, EventArgs e)

db.openConnection();

SqlCommand cmd = new SqlCommand("get_male_student", db.getConnection);

cmd.CommandType = CommandType.StoredProcedure;

SqlDataAdapter adapter = new SqlDataAdapter(cmd);

DataTable dt = new DataTable();

adapter.Fill(dt);

dgv_information.DataSource = dt;

db.closeConnection();

private void btn_selectFemale_Click(object sender, EventArgs e)

string query = "SELECT * FROM f_female_student()";

db.openConnection();

SqlCommand cmd = new SqlCommand(query, db.getConnection);

SqlDataAdapter Adapter = new SqlDataAdapter(cmd);

DataTable dt = new DataTable();


Adapter.Fill(dt);

dgv_information.DataSource = dt;

db.closeConnection();

Source code connect database:

internal class MyDB

SqlConnection connection = null;

public MyDB() {

connection = new SqlConnection(@"Data Source=NHAATJNGUYEEN;Initial


Catalog=Student;Integrated Security=True");

public SqlConnection getConnection

get

return connection;

public void openConnection()

if(connection.State == ConnectionState.Closed)

connection.Open();

}
public void closeConnection()

if (connection.State == ConnectionState.Open)

connection.Close();

Procedure button:
Function button:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy