发布网友 发布时间:2022-04-08 19:07
共6个回答
懂视网 时间:2022-04-08 23:29
static class SqlHelper { public static object FromDbValue(object value) { if (value == DBNull.Value) { return null; } else { return value; } } public static object ToDbValue(object value) { if (value == null) { return DBNull.Value; } else { return value; } } private static string connStr = ConfigurationManager.ConnectionStrings["myconnstring"].ConnectionString; public static int ExecuteNonQuery(string sql, params SqlParameter[] parameters) { using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.Parameters.AddRange(parameters); return cmd.ExecuteNonQuery(); } } } public static object ExecuteScalar(string sql, params SqlParameter[] parameters) { using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.Parameters.AddRange(parameters); return cmd.ExecuteScalar(); } } } public static DataTable ExecuteDataTable(string sql, params SqlParameter[] parameters) { using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.Parameters.AddRange(parameters); DataSet dataset = new DataSet(); SqlDataAdapter apdater = new SqlDataAdapter(cmd); apdater.Fill(dataset); return dataset.Tables[0]; } } } public static DataSet ExecuteDataSet(string sql, params SqlParameter[] parameters) { using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; cmd.Parameters.AddRange(parameters); DataSet dataset = new DataSet(); SqlDataAdapter apdater = new SqlDataAdapter(cmd); apdater.Fill(dataset); return dataset; } } } } View Code
SqlHelper.cs
标签:
热心网友 时间:2022-04-08 20:37
是析构函数热心网友 时间:2022-04-08 21:55
应该是析构吧热心网友 时间:2022-04-08 23:29
析构函数参考资料:http://msdn.microsoft.com/zh-cn/library/66x5fx1b(VS.80).aspx
热心网友 时间:2022-04-09 01:21
析构函数热心网友 时间:2022-04-09 03:29
这种写法是畸形的,.net不会显示调用析构函数用以释放对象.