public static class DB { static MySqlConnection con = new MySqlConnection("server=127.0.0.1;uid=root;pwd=root;database=mydb"); public static DataTable Query(string sql) //创建查询方法 { MySqlDataAdapter sda = new MySqlDataAdapter(sql, con); DataTable dt = new DataTable(); sda.Fill(dt); return dt; } public static int Edit(string sql)//创建增删改方法 { con.Open(); MySqlCommand com = new MySqlCommand(sql, con); int a = com.ExecuteNonQuery(); con.Close(); return a; } }
标签:c#,sql,DataTable,public,static,mysql,new,连接,con From: https://www.cnblogs.com/ThisYbc/p/16794282.html