In fact, dataadapter uses the sqlcommand object to execute the stored procedure:
1 Private Dataset getdataset ()
2 {
3
4 Sqlconnection Conn = Dbhelper. getconn (); // Get database connection with help class
5 Sqlcommand cmd = New Sqlcommand ( " Proc_name " , Conn ); // Obtain the sqlcommand object
6 Cmd. commandtype = Commandtype. storedprocedure; // Specify the name of a stored procedure instead of an SQL statement when the sqlcommand object is created.
7 Dataset DS = New Dataset (); // Create a dataset for storing the result set
8 Conn. open (); // Open Database
9 Sqldataadapter DAP = New Sqldataadapter (); // Create a sqldataadapter object
10 Dap. selectcommand = CMD; // Using cmd to execute the stored procedure, sqldataadapter only needs to specify the sqlcommand type (also, deletecommand, insertcommand, updatecommand)
11 Dap. Fill (DS, " Student " ); // Fill Dataset
12 Conn. Close ();
13 Return DS;
14 }
Selectcommand is called in sqldataadapter. Fill (), updatecommand, insertcommand, and deletecommand are called in sqldataadapter. Update.