//引入標頭檔案
using mysql.data.mysqlclient;
//連線操作
string constr = 「database = test007;data source = 127.0.0.1;port = 3306;user id =root;password = root;」
mysqlconnection conn = new mysqlconnection(constr);
//開啟資料庫
conn.open();
//建立一條mysql語句
mysqlcommand cmd = new mysqlcommand(「select * from user」, conn)
//建立mysql流
mysqldatareader reader = cmd.executereader();
while (reader.read()) 每次讀取一行,連續呼叫,一直下一行下一行
reader.close(); //讀取完後,必須關閉流
//寫入一條mysql
cmd.executenonquery();
conn.close(); //操作完成後,需要關閉資料庫
mysql注入問題
原因:字串拼接的方式,如果值的內容包含了一條mysql語句,則會被執行到。
解決方式,採用賦值方式
string username = 「haha」; string password = 「haha;delete from user;」;
mysqlcommand cmd = new mysqlcommand(「insert into user set username = @un,password = @pwd」, conn);
cmd.parameters.addwithvalue(「un」, username);
cmd.parameters.addwithvalue(「pwd」, password);
cmd.executenonquery();
c 運算元據庫
namespace ec region sql資料庫備份 sql資料庫備份 sql伺服器ip或 localhost 資料庫登入名 資料庫登入密碼 資料庫名 備份到的路徑 public static void sqlback string serverip,string loginname,strin...
C 運算元據庫
先從資料庫中取出結果集後進行處理資料後再update更新到資料庫。如果只想讀取和顯示資料,只需要使用資料讀取sqldatareader即可,但要處理資料然後更新資料庫 增加 更改 局需要資料集dataset和資料介面卡sqldataadaper。sqldataadapter的用法 讀取資料用sqld...
C 運算元據庫
先上 using system using system.collections.generic using system.linq using system.text using system.threading.tasks using system.data using system.data....