Using
In using Code Creates short-lived objects at all possible locations in the block.
Use nextresult () to retrieve multiple result sets Sqlconnection con = New Sqlconnection ( " Data Source = (local); initial catalog = threelayer; persist Security info = false; user id = sa; Password =; " );
Con. open ();
Sqlcommand cmd = Con. createcommand ();
Cmd. commandtext = " Select * from limit; select * From message " ;
Sqldatareader Dr = Cmd. executereader ();
// Use nextresult () to retrieve multiple result sets
// Do
// {
// While (dr. Read ())
// {
// Console. Write ("{0}-{1}", Dr [0], Dr [1]);
// Console. writeline ();
// }
// } While (dr. nextresult ());
// Read () method to get
While (Dr. Read ())
{
Console. Write ("{0}-{1}", Dr [0], Dr [1]);
Console. writeline ();
}
Dr. Close ();
Con. Close ();
Parameterized Query
String Strconn, strsql;
Strconn = @" Data Source =. \ sqlexpress; " +
" Initial catalog = northwind; Integrated Security = true; " ;
Strsql = " Select @ unitprice = unitprice, @ unitsinstock = unitsinstock " +
" From products where productname = @ productname " ;
Sqlconnection CN = New Sqlconnection (strconn );
CN. open ();
Sqlcommand cmd = New Sqlcommand (strsql, CN );
Sqlparameter punitprice, pinstock, pproductname;
Punitprice = Cmd. Parameters. Add ( " @ Unitprice " , Sqldbtype. Money );
Punitprice. Direction = Parameterdirection. output;
Pinstock = Cmd. Parameters. Add ( " @ Unitsinstock " , Sqldbtype. nvarchar, 20 );
Pinstock. Direction = Parameterdirection. output;
Pproductname = Cmd. Parameters. Add ( " @ Productname " , Sqldbtype. nvarchar, 40 );
Pproductname. Value = " Chai " ;
Cmd. executenonquery ();
If (Punitprice. Value = Dbnull. value) {
Console. writeline ("No product found named {0}", Pproductname. value );
} Else {
Console. writeline ("Unit Price: {0}", Punitprice. value );
Console. writeline ("In stock: {0}", Pinstock. value );
}
Set a null value to dbnull. value.
Back to ojbect []
New object [] {...}
Datatable [] tables = new datatable () {Ds. Table [1], DS. Table [1]}
Add row loaddatarow