1 usingsystem;2 usingmysql.data.mysqlclient;3
4 namespacemysql資料庫操作5 29 //
30 31 #endregion
33 #region 插入
34 // //正常插入一條資料35 //string username = "lj";string password = "6666";36 //mysqlcommand cmd = new mysqlcommand("insert into user set username ='" + username + "'" + ",password='" + password + "'", conn);37
39 // //sql 注入,會刪除資料庫40 //string username = "lj"; string password = "6666'; delete from user;";41 //mysqlcommand cmd = new mysqlcommand("insert into user set username ='" + username + "'" + ",password='" + password + "'", conn);42
44 // //防止注入,不會執行刪除資料庫語句45 //string username = "lj"; string password = "6666'; delete from user;";46 //mysqlcommand cmd = new mysqlcommand("insert into user set username=@uid , password = @pwd", conn);47 "uid", username);48 "pwd", password);49
50 #endregion
52 #region 刪除
53 // //刪除 id 為 6 的條目54 //mysqlcommand cmd = new mysqlcommand("delete from user where id = @id", conn);55 "id", 6);56 //
57 58 #endregion
60 #region 更新
61 //將 id 為 7 的條目 pwd 修改為 lll
62 mysqlcommand cmd = new mysqlcommand("update user set password = @pwd where id = 7", conn);63 cmd.parameters.addwithvalue("pwd", "lll");64
65 cmd.executenonquery();66 #endregion
68 conn.close();69
70 console.readkey();71 }72 }73 }
C mysql資料操作
using system using system.collections.generic using system.linq using system.text using system.data using mysql.data.mysqlclient using mysql.data name...
c mysql 選擇 C 操作MySQL的類
c 操作mysql的類 public class mysqlservice private static log4net.ilog logger log4net.logmanager.getlogger typeof mysqlservice server localhost user id roo...
C MySQL資料庫操作例項
環境設定 示例 include windows.h include stdio.h include stdlib.h include string h include mysql.h include iostream using namespace std intmain j mysql num f...