using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; namespace WindowsFormsApplication1 { class DBhelper { public static SqlConnection conn; public static void connection() { conn = new SqlConnection(); conn.Open(); } //增加 public static bool adm(string sqla) { connection(); SqlCommand com = new SqlCommand(sqla, conn); int pass = com.ExecuteNonQuery(); conn.Close(); return pass > 0; } //查询 public static DataTable selectDB(string sqla) { DataTable dt = new DataTable(); SqlDataAdapter dap = new SqlDataAdapter(sqla, conn); dap.Fill(dt); conn.Close(); return dt; } } }