public static int NonQuery(string sql) { int num = 0; SqlConnection sql Connection = new SqlConnection (strConn) ; SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection) ; try { sqlConnection. Open() ; num =sqlCommand. ExecuteNonQuery() ; }
finally //不管try出不出问题都会执行
——DBHelper
public DataTable Query(string sql) {
SqlConnection conn = new SqlConnection(str); conn.Open(); SqlDataAdapter da = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); da.Fill(dt); conn.Close(); return dt; } //定义添加的方法 public int excuate(string sql) { SqlConnection conn = new SqlConnection(str); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); int num = comm.ExecuteNonQuery(); return num; }