using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; using System.Configuration; using System.Data; namespace 收费系统 { class SQLhelper { public static int ExecuteNonQuery(string sql, params SqlParameter[] parameters) { string Constrs = ConfigurationManager.ConnectionStrings["Connstrs"].ConnectionString; using (SqlConnection conn = new SqlConnection(Constrs)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; foreach (SqlParameter parameter in parameters) { cmd.Parameters.Add(parameter); } return cmd.ExecuteNonQuery(); } } } public static DataTable ExecuteDataTable(string sql, params SqlParameter[] parameters) { string Constrs = ConfigurationManager.ConnectionStrings["Connstrs"].ConnectionString; using (SqlConnection conn = new SqlConnection(Constrs)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; foreach (SqlParameter parameter in parameters) { cmd.Parameters.Add(parameter); } DataSet dataset = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(dataset); return dataset.Tables[0]; } } } } }