0% found this document useful (0 votes)
18 views

Them 2 Thu Vien Sau Vao: Using Using Using Using Using Using Namespace Class String

This document contains code for connecting to a SQL database and performing basic operations like selecting, inserting, updating, and deleting data. It defines a class called "KetnoiSQL" that contains methods for opening and closing a SQL connection, selecting data using a SQL statement, and executing INSERT, UPDATE, or DELETE statements. The connection string points to a SQL Server Express database named "CSDL".
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Them 2 Thu Vien Sau Vao: Using Using Using Using Using Using Namespace Class String

This document contains code for connecting to a SQL database and performing basic operations like selecting, inserting, updating, and deleting data. It defines a class called "KetnoiSQL" that contains methods for opening and closing a SQL connection, selecting data using a SQL statement, and executing INSERT, UPDATE, or DELETE statements. The connection string points to a SQL Server Express database named "CSDL".
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System; using System.Collections.Generic; using System.Linq; using System.Text; // them 2 thu vien sau vao using System.Data.

SqlClient; using System.Data; namespace ControlCentre { class KetnoiSQL { string sqlconnecttion = @"Data Source=XUANDONG\SQLEXPRESS;Initial Catalog=CSDL;Integrated Security=True"; // tao duong dan toi CSDL SqlConnection conn = new SqlConnection(); public static SqlCommand cmd; public void Open() { conn = new SqlConnection(sqlconnecttion); //conn.ConnectionString = sqlconnecttion; conn.Open(); } public void Close() { //conn.ConnectionString = sql; conn.Close(); // dong ket noi conn.Dispose(); // giai phong tai nguyen // conn = null; // giai phong doi tuong } public SqlDataReader Select(string sql) { SqlDataReader reader; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = sql; reader = cmd.ExecuteReader(); return reader; } public void Insert_Update_Delete(string sql) { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = sql; cmd.ExecuteNonQuery();

} } }

You might also like