用c 鏈結資料庫

2021-10-10 15:10:25 字數 1014 閱讀 3467

1.建立連線字串

string a = 「data source=.;initial catalog=qq;integrated security=true」;

12.建立連線物件

sqlconnection connection = new sqlconnection(a);

1執行乙個sql語句

1.將想要執行的sql語句放入乙個變數

2.執行sql語句需要乙個執行者,.建立乙個執法者(例項化command物件)

sqlcommand cmd = new sqlcommand(裝sql語句的變數, 連線物件);

1注:在執行之前需將connection開啟

連線物件.open();開啟

執行命令物件的sql語句

executenonquery();

返回乙個int型別變數,如果sql語句是對資料庫的記錄進行操作(如記錄的增加、刪除和更新),那麼方法將返回操作所影響的記錄條數。

如果sql語句是對資料庫的記錄進行操作(如記錄的增加、刪除和更新),那麼方法將返回操作所影響的記錄條數。

executescalar();

執行命令物件的sql語句,如果sql語句是select查詢,則僅僅返回查詢結果集中的第1行第1列,而忽略其他的行 和列。該方法所返回的結果為object型別,在使用之前必須強制轉換為所需的型別。如果sql語句不是select查詢,則返回結果沒有任何作用。

如果sql語句是select查詢,則僅僅返回查詢結果集中的第1行第1列

executereader();

執行命令物件的sql語句,在ado.net中,就是datareader 物件的executereader()方法來進行資料的列出,並且我們用這個executereader()方法來顯示資料是最快的一種方法,因為當我們在用executereader()方法中的datareader 物件來進行資料的在**建設中顯示時,他只可以一條一條向前讀,不能返回,也就是像asp中的ado方法中的recordset 物件的movenext一樣,它沒有move -1這樣的返回方法。

用C 鏈結ORACLE資料庫

standard security provider msdaora data source myoracledb user id username password asdasd this one s from microsoft,the following are from oracle sta...

c 鏈結資料庫

c 連線access程式 using system.data using system.data.oledb string strconnection provider microsoft.jet.oledb.4.0 strconnection data source c begaspnetnort...

C 鏈結ORACLE資料庫

using system using system.data using system.configuration using system.linq using system.web using system.web.security using system.web.ui using syste...