需要mysql.data.dll
資料庫連線
//server資料庫位址,user資料庫使用者名稱,password密碼,database資料庫名
string connectstring = string.format("server=;user id=;password=;database=;", server, user, password, database);
mysqlconnection conn = new mysqlconnection(connectstring );
conn.open();
//加資料庫操作
conn.close();
conn.dispose();
新增
mysqlcommand command = conn.createcommand();
string str = "insert into (id,name)values('','')";
//表名,欄位id的值,欄位name的值
command.commandtext = string.format(str, table, id, name);
command.executenonquery();
刪除
mysqlcommand command = conn.createcommand();
string str = string.format("delete from where id=''", table, idnumber);
command.commandtext = str;
command.executenonquery();
修改
mysqlcommand command = conn.createcommand();
string str = "update set id='',name=''"
;command.commandtext = string.format(str, table, id, name);
command.executenonquery();
清空表
mysqlcommand command = conn.createcommand();
string str = string.format("truncate table ", table);
command.commandtext = str;
command.executenonquery();
查詢
string command = string.format("select * from ", table);//
mysqlcommand mycmd = new mysqlcommand(command, conn);
mysqldataadapter adapter = new mysqldataadapter(mycmd);
dataset ds = new dataset();
adapter.fill(ds);
for (int i = 0; i < ds.tables[0].rows.count; i++)
c 操作mysql資料庫
include include stdio.h include winsock.h include mysql.h int main else else sprintf tmp,update s set 商品 s 賣出 d,成交 d,漲跌 d,買進 d,總量 d,漲幅 f,時間 s where s ...
C 操作MYSQL資料庫
1.安裝mysql 略2.建立c 控制台程式,新建cpp原始檔,如 sqlconn.cpp 3.在工程專案中屬性 c c 常規 附加包含目錄中新增mysql安裝目錄中的mysql mysql mysql server 5.7 include 4.新增庫目錄 5.新增依賴項 libmysql.lib ...
C 操作mysql資料庫
採用c 封裝mysql提供的常用庫函式,實現對mysql資料庫的訪問。版本歷史 1 建立表的示例程式 createtable.cpp 本程式演示建立乙個表,用於存放商品資訊。include freemysql.h int main int argc,char argv 設定字符集為 gbk 與mys...