标签:tab get string col mes table ring opera mysql
C#操作Mysql的简单、基础方法:
1 class MysqlManager
2 {
3 MySqlConnection conn;
4
5 public MysqlManager(string strConn)
6 {
7 conn = new MySqlConnection(strConn);
8 }
9
10 public DataTable GetData(string strCmd)
11 {
12 try
13 {
14 MySqlDataAdapter adpt = new MySqlDataAdapter(strCmd, conn);
15 DataTable dt = new DataTable();
16 adpt.Fill(dt);
17 return dt;
18 }
19 catch(Exception ex)
20 {
21 MessageBox.Show(ex.Message, "Error-GetData", MessageBoxButtons.OK, MessageBoxIcon.Error);
22 return null;
23 }
24 finally
25 {
26 if (conn.State == ConnectionState.Open) conn.Close();
27 }
28 }
29
30 public void Operate(string strCmd)
31 {
32 try
33 {
34 conn.Open();
35 MySqlCommand cmd = new MySqlCommand(strCmd, conn);
36 cmd.ExecuteNonQuery();
37 conn.Close();
38 }
39 catch (Exception ex)
40 {
41 MessageBox.Show(ex.Message, "Error-Operate", MessageBoxButtons.OK, MessageBoxIcon.Error);
42 }
43 finally
44 {
45 if (conn.State == ConnectionState.Open) conn.Close();
46 }
47 }
48 }
标签:tab get string col mes table ring opera mysql
原文地址:http://www.cnblogs.com/ljsoftware/p/7531352.html