string con = ConfigurationSettings.AppSettings [ "dsn"]; SqlConnection conn = new SqlConnection (con); // connection string conn.Open (); SqlDataAdapter myCommand = new SqlDataAdapter (); // Create a class myCommand.SelectCommand = new SqlDataAdapter SqlCommand ( "sp_searchCkArticleByTitle", conn); myCommand.SelectCommand.CommandType = CommandType.StoredProcedure; SqlParameter title = myCommand.SelectCommand.Parameters.Add ( "@ title", SqlDbType.NVarChar, 500); title.Value = Request [ "keyword "]; DataSet DS = new dataset (); // Established and fill the data set MyCommand.Fill (DS," Articl "); mydatagrid.dataSource = DS; mydatagrid.databind ();
Why mycommand.selectcommand = new sqlcommand ("sp_searchckarticlebytitle"; CONN); this can directly call the storage process, without prior declaration, instantiate. SqlDataAdapter class has declared, such an interface is much more. Note that you can see that the statement is to refer to this? Mycommand.selectcommand.commandtype = commandType.StoredProcedure;
In MyCommand.fill (DS, "Articl"); the CommandType passes the database server when the line is executed, and it is set to it.