C 訪問MySQL資料庫的方法

2021-09-30 13:23:16 字數 2207 閱讀 2961

(2)安裝mysql-connector-net

然後直接在windows作業系統安裝 mysql-connector-net-6.3.8.msi

預設是安裝在c盤:

c:\program files\mysql\mysql connector net 6.3.8\assemblies

v2.0

v4.0

安裝完後我選擇的是v2.0版本的

然後在應用工程中引用元件mysql.data.dll

(3)封裝資料庫訪問元件dbconnectionmysql

this.m_dbconn = new mysqlconnection(pconnectionstring);  

this.m_dbconnstate = dbconnstate.free;

} //--

public override dbdataadapter getdbdataadapter()

public override dbdataadapter getdbdataadapter(dbcommand dbcommand)

public override dbcommand getdbcommand()

public override dbconnection getdbconnection()

public override dbcommandbuilder getdbcommandbuilder()

public override dataprovidertype getcurrentdataprovidertype()

public override bool i***iststable(string tablename, string username)

else

} else

return rbc;

#endregion

} public override bool i***istsfield(string fieldname, string tablename)

} dt.dispose();

dt = null;

} ds.dispose();

ds = null;

return_end:

return rbc;

#endregion

} public override char parameterchar

} public override dbparameter createparameter(string name, object value)

public override dbparameter createparameter(string name)

public override dbparameter createparameter(string name, dbtype dbtype, object value)

public override dbparameter createparameter(string name, dbtype dbtype, int size, object value)

}

(4)客戶端訪問測試開發例項

string x = "";  

//刪除語句

x = "delete from xp_users";

if (dbw.executequery(x) > 0)

//插入語句

x = "insert into xp_users(gid,uid,uname,***,email,pwd) values('";

x += "1','hsg77','何***',1,'[email protected]','1')";

if (dbw.executequery(x) > 0)

//查詢語句

datatable dt = dbw.executedatatable("select * from xp_users");

if (dt != null && dt.rows.count > 0)

if (dt != null)

dbw.dispose();

dbw = null;

}

—-the—end—

create date:2012-02-28

C 訪問mysql資料庫的方法

資料庫 2009 01 19 09 50 28 閱讀1126 字型大小 大 中小訂閱 資料庫的連線 mysqlconnection conn new mysqlconnection database phpcms2008 data source localhost user id root pass...

C 訪問MySQL資料庫的方法

c 訪問mysql資料庫的方法 2 安裝mysql connector net 然後直接在windows作業系統安裝mysql connector net 6.3.8.msi 預設是安裝在c盤 c program files mysql mysql connector net 6.3.8 assem...

C 訪問MySQL資料庫的方法

c 訪問mysql資料庫的方法 2 安裝mysql connector net 然後直接在windows作業系統安裝mysql connector net 6.3.8.msi 預設是安裝在c盤 c program files mysql mysql connector net 6.3.8 assem...