一:c#資料庫查詢之資料庫連線**:
sqlconnectionobjsqlconnection=newsqlconnection(二:資料庫的新增記錄**:"server=127.0.0.1;uid=sa;pwd=;database=test"
);
objsqlconnection.
open
();
inti=0;三:資料庫的修改**:strings1=
"",s2=
"";
i=convert
.toint16(textbox1.text);
s1=textbox2.text;
s2=textbox3.text;
sqlconnectionobjsqlconnection=newsqlconnection(
"server=127.0.0.1;uid=sa;pwd=;database=test"
);
objsqlconnection.
open
();
messagebox.show(
"資料庫連線成功"
,"好"
);
try
catch(exceptiona)
messagebox.show(
"新增成功!"
,"啊"
);
}
inti=0;四:資料庫的刪除**:strings1=
"",s2=
"";
s1=textbox2.text;
s2=textbox3.text;
if(textbox1.text.length==0)
i=0;
else
i=convert
.toint32(textbox1.text);
sqlconnectionobjsqlconnection=newsqlconnection(
"server=127.0.0.1;uid=sa;pwd=;database=test"
);
objsqlconnection.
open
();
messagebox.show(
"資料庫連線成功"
,"好"
);
try
catch(exceptiona)
inti=0;五:資料庫的查詢**:strings1=
"",s2=
"";
s1=textbox2.text;
s2=textbox3.text;
if(textbox1.text.length==0)
i=0;
else
i=convert.toint16(textbox1.text);
sqlconnectionobjsqlconnection=newsqlconnection(
"server=127.0.0.1;uid=sa;pwd=;database=test"
);
objsqlconnection.open();
messagebox.show(
"資料庫連線成功"
,"好"
);
try
catch
(exceptiona)
1.類開始:
datatabledt1=newdatatable();2.按鈕**:sqldataadapterda1=newsqldataadapter();
inti=0,n=0;六:c#資料庫查詢**:strings1=
"",s2=
"";
s1=textbox2.text;
s2=textbox3.text;
if(textbox1.text.length==0)
i=0;
else
i=convert
.toint32(textbox1.text);
sqlconnectionobjsqlconnection=newsqlconnection(
"server=127.0.0.1;uid=sa;pwd=;database=test"
);
objsqlconnection.
open
();
messagebox.show(
"資料庫連線成功"
,"好"
);
stringquery=
"select*frominfowhereid="
+i;
datasetobjdataset=newdataset();
sqldataadapterobj=newsqldataadapter();
obj.selectcommand=newsqlcommand(query,objsqlconnection);
obj.fill(objdataset,
"info"
);
sqlcommandobjsqlcommand=newsqlcommand(query,objsqlconnection);
sqldatareaderobjsqlreader=objsqlcommand.executereader();
while(objsqlreader.
read
())
if(n==0)
messagebox.show(
"資料庫中沒有這樣的記錄!"
);
inti=0;c#資料庫查詢之資料庫的封裝類**://intn=0;
strings1=
"",s2=
"";
stringsql;
s1=textbox2.text;
s2=textbox3.text;
if(textbox1.text.length==0)
else
i=convert.toint32(textbox1.text);
sqlconnectionobjsqlconnection=newsqlconnection(
"server=127.0.0.1;uid=sa;pwd=;database=test"
);
objsqlconnection.open();
messagebox.show(
"資料庫連線成功"
,"好"
);
stringquery=
"select*frominfowhereid="
+i;
if(i==0)
sql=
"select*frominfo"
; else
sql=
"select*frominfowhereid="
+i;
da1=newsqldataadapter(sql,objsqlconnection);
dt1.clear();
da1.fill(dt1);
datagridview1.datasource=dt1;
classdbclasscatch
(exceptiona)
} } --db2資料庫連線**:
stringstrcon=
"provider=ibmdadb2;datasource=hfzd;userid=db2admin;password=db2admin"
; //stringsql="select*fromadministrator.hfzd";
stringsql=
"deletefromadministrator.hfzdwhereid=1"
; oledbconnectionolecon=newoledbconnection(strcon);
olecon.open();
messagebox.show(
"資料庫已連線上"
);
dt.clear();
da=newoledbdataadapter(sql,olecon);
da.fill(dt);
datagridview1.datasource=dt;
olecon.close();
C 對資料庫各種操作
using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...
C 對資料庫各種操作
using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...
C 中資料庫操作
using system using system.data using system.data.sqlclient using system.web namespace moban 連線資料庫引數 public string con set 資料庫連線引數 public sqlconnection...