Idle to Nothing, and SqlHelper knocked again.
In general, each programmer will prefer to write with their own sqlhelper, use it handy, hehe.
Public classSqlHelper { Public Static ReadOnly stringstr = configurationmanager.connectionstrings["Constr"]. ConnectionString; /// <summary> ///This method can be used with SQL statements or stored procedures///executes Transact-SQL statements on the connection and returns the number of rows affected. /// </summary> /// <param name= "SQL" ></param> /// <param name= "ComType" >CommandType</param> /// <param name= "Para" >variable Parameters</param> /// <returns>the number of rows affected. </returns> Public Static intExecuteNonQuery (stringSQL, CommandType ComType,paramsSqlparameter[]para) { using(SqlConnection con=NewSqlConnection (str)) { using(SqlCommand cmd=NewSqlCommand (Sql,con)) {con. Open (); if(para!=NULL) {cmd. Parameters.addrange (para); } Cmd.commandtype=ComType; returncmd. ExecuteNonQuery (); } } } /// <summary> ///This method can be used with SQL statements or stored procedures///executes the query and returns the first column of the first row in the result set returned by the query. Other columns or rows are ignored. /// </summary> /// <param name= "SQL" ></param> /// <param name= "ComType" ></param> /// <param name= "para" ></param> /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty (Nothing in Visual Basic). The maximum number of characters returned is 2033 characters. </returns> Public Static ObjectExecuteScalar (stringSQL, CommandType ComType,paramssqlparameter[] para) { using(SqlConnection con =NewSqlConnection (str)) { using(SqlCommand cmd =NewSqlCommand (sql, con)) {con. Open (); if(Para! =NULL) {cmd. Parameters.addrange (para); } Cmd.commandtype=ComType; returncmd. ExecuteScalar (); } } } /// <summary> ///executes the query and returns the first column of the first row in the result set returned by the query. Other columns or rows are ignored. ///send the System.Data.SqlClient.SqlCommand.CommandText to System.Data.SqlClient.SqlCommand.Connection and use the/// </summary> /// <param name= "SQL" ></param> /// <param name= "ComType" ></param> /// <param name= "para" ></param> /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty (Nothing in Visual Basic). The maximum number of characters returned is 2033 characters. A System.Data.SqlClient.SqlDataReader object. </returns> Public StaticSqlDataReader ExecuteReader (stringSQL, CommandType ComType,paramssqlparameter[] para) {SqlConnection con=NewSqlConnection (str); using(SqlCommand cmd=NewSqlCommand (Sql,con)) { if(Para! =NULL) {cmd. Parameters.addrange (para); } Try{con. Open (); Cmd.commandtype=ComType; returncmd. ExecuteReader (commandbehavior.closeconnection); } Catch(Exception) {con. Close (); Con. Dispose (); Throw; } } } /// <summary> ///Query by Saldataadapter/// </summary> /// <param name= "SQL" ></param> /// <param name= "param" ></param> /// <returns>The return is a table</returns> Public StaticDataTable GetTable (stringSqlparamssqlparameter[] param) {DataTable dt=NewDataTable (); using(SqlConnection con =NewSqlConnection (str)) { using(SqlCommand cmd =NewSqlCommand (sql, con)) {cmd. Parameters.addrange (param); using(SqlDataAdapter SDA =NewSqlDataAdapter (CMD)) {SDA. Fill (DT); } } } returnDT; } /// <summary> ///Query by Saldataadapter/// </summary> /// <param name= "SQL" ></param> /// <param name= "param" ></param> /// <returns>The return is a table</returns> Public StaticDataTable GetTable (stringSqlparamssqlparameter[] param) {DataTable dt=NewDataTable (); using(SqlConnection con =NewSqlConnection (str)) { using(SqlCommand cmd =NewSqlCommand (sql, con)) {cmd. Parameters.addrange (param); using(SqlDataAdapter SDA =NewSqlDataAdapter (CMD)) {SDA. Fill (DT); } } } returnDT; } }