First you have to get an instance of SqlConnection object con, which is used below (as for how to connect the database, I don't need to say it)
SQL statement
SqlCommand cmd = new SqlCommand ("SELECT * from Bbsboards where boardsortid=1", con);
SqlDataAdapter ad = new SqlDataAdapter ("select * from Bbsboards where boardsortid=1", con);
Ad. Fill (DS);
Stored Procedures
(1) No parameters
SqlCommand cmd = new SqlCommand ("Getboards", con);
Cmd.commandtype = CommandType.StoredProcedure;
(2) parameters (with input parameters, output parameters and two return result sets)
SqlCommand cmd = new SqlCommand ("Getboardsbysortid", con);
Cmd.commandtype = CommandType.StoredProcedure;
Cmd. Parameters.Add (New SqlParameter ("@sortid", 1));
Set OUTPUT parameters
SqlParameter sp = new SqlParameter ();
Sp. DbType = Dbtype.int32;
Sp. Direction = ParameterDirection.Output;
Sp. ParameterName = "@a";
Cmd. Parameters.Add (SP);
Set return value
SqlParameter p = new SqlParameter ();
P.dbtype = Dbtype.int32;
P.direction = ParameterDirection.ReturnValue;
Cmd. Parameters.Add (P);
SqlDataReader ad = cmd. ExecuteReader ();
This. Gridview1.datasource = AD; Here, I bind the result set directly to the GridView.
This. Gridview1.databind ();
Return multiple result sets
Ad. NextResult ();
This. Gridview2.datasource = AD; Here, I bind the result set directly to the GridView.
This. Gridview2.databind ();
Con. Close ();
Get return value (must be after con.close ())
P.value.tostring ();
Get output parameter values
sp. Value.tostring ();