自己动手写SqlHelper类!
using System;
using System.Collections.Generic;using System.Configuration;using System.Data.SqlClient;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WpfApplication1_dataset_离线数据集
{ class SqlHelper { private static string connStr = ConfigurationManager.ConnectionStrings["dbConnstr"].ConnectionString; public static int ExecuteNonQuery(string sql) { using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; return cmd.ExecuteNonQuery(); } } } public static object ExecuteScalar(string sql) { using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; return cmd.ExecuteScalar(); } } } }}