Self-taught. NET has been fast for one months, watching the video of the SqlHelper podcast, just apply for a blog today, first put the handwritten class upload it up
Don't forget to add system.configuration in the solution manager's references
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Configuration;6 usingSystem.Data.SqlClient;7 usingSystem.Data;8 9 namespaceSHTen { One classSqlHelper A { - Private Static stringConnStr = configurationmanager.connectionstrings["Dbconnstr"]
. ConnectionString; - the - Public Static intExecuteNonQuery (stringSqlparamssqlparameter[] Parameters) - { - using(SqlConnection conn =NewSqlConnection (connstr)) + { - Conn. Open (); + using(SqlCommand cmd =Conn. CreateCommand ()) A { atCmd.commandtext =SQL; - //foreach (SqlParameter param in parameters) - //{ - //cmd. Parameters.Add (param); - //} - cmd. Parameters.addrange (Parameters); in returncmd. ExecuteNonQuery (); - } to } + } - the Public Static ObjectExecuteScalar (stringSqlparamssqlparameter[] Parameters) * { $ using(SqlConnection conn =NewSqlConnection (connstr))Panax Notoginseng { - Conn. Open (); the using(SqlCommand cmd =Conn. CreateCommand ()) + { ACmd.commandtext =SQL; the cmd. Parameters.addrange (Parameters); + returncmd. ExecuteScalar (); - } $ } $ } - - //SQL that is used only to execute fewer query results the Public StaticDataTable executedatatable (stringSqlparamssqlparameter[] Parameters) - {Wuyi using(SqlConnection conn =NewSqlConnection (connstr)) the { - Conn. Open (); Wu using(SqlCommand cmd =Conn. CreateCommand ()) - { AboutCmd.commandtext =SQL; $ cmd. Parameters.addrange (Parameters); - -SqlDataAdapter adapter =NewSqlDataAdapter (cmd); -DataSet DataSet =NewDataSet (); A adapter. Fill (dataset); + returnDataSet. tables[0]; the } - } $ } the } the}
Self-study. NET (1) handwriting a SqlHelper class