First join the namespace using System.Data.SqlClient;
1. Enquiry
SqlConnection conn = new SqlConnection ();
Conn. ConnectionString = "Data source= (local); Initial catalog= database name; Userid=sa; password=123456 ";
Conn. Open ();
String strsql= "SELECT statement";
SqlCommand cmd = new SqlCommand (strSQL, conn);
SqlDataReader sqlreader = cmd. ExecuteReader ();
while (Sqlreader. Read ())
{
txtname.text= sqlreader["column name"]. ToString ();
}
Sqlreader. Close ();
Conn. Close ();
2. Insert, UPDATE, delete
SqlConnection conn = new SqlConnection ();
Conn. ConnectionString = "Data source= (local); Initial catalog= database name; Userid=sa; password=123456 ";
Conn. Open ();
strsql= "UPDATE statement";//strsql= "INSERT statement";//strsql= "DELETE statement";
SqlCommand sqlcmd2 = new SqlCommand (strSQL, conn);
int iresult = SQLCMD2. ExecuteNonQuery ();
Conn. Close ();
ASP. NET (C #) connection database and operational database