![預(yù)習(xí)中軟國(guó)際卓越培訓(xùn)中心_第1頁(yè)](http://file4.renrendoc.com/view/8880cf9cce1e62b07955c3c6ae62114a/8880cf9cce1e62b07955c3c6ae62114a1.gif)
![預(yù)習(xí)中軟國(guó)際卓越培訓(xùn)中心_第2頁(yè)](http://file4.renrendoc.com/view/8880cf9cce1e62b07955c3c6ae62114a/8880cf9cce1e62b07955c3c6ae62114a2.gif)
![預(yù)習(xí)中軟國(guó)際卓越培訓(xùn)中心_第3頁(yè)](http://file4.renrendoc.com/view/8880cf9cce1e62b07955c3c6ae62114a/8880cf9cce1e62b07955c3c6ae62114a3.gif)
![預(yù)習(xí)中軟國(guó)際卓越培訓(xùn)中心_第4頁(yè)](http://file4.renrendoc.com/view/8880cf9cce1e62b07955c3c6ae62114a/8880cf9cce1e62b07955c3c6ae62114a4.gif)
![預(yù)習(xí)中軟國(guó)際卓越培訓(xùn)中心_第5頁(yè)](http://file4.renrendoc.com/view/8880cf9cce1e62b07955c3c6ae62114a/8880cf9cce1e62b07955c3c6ae62114a5.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
ADO(ActiveDataObjects)是 續(xù)技術(shù),提供對(duì)SQLSEVER等數(shù)據(jù)源的一致 (SQLSERVER\ACCESS\OLEDB等),ADO.NETDataSet是ADO.NET結(jié)構(gòu)的 元素是.NETFramawork 目前,.NETFramawork附帶了兩個(gè)數(shù)據(jù)提供程序:SQLServer和OLEDB數(shù)據(jù)提供程序。OLEDB數(shù)據(jù)提供程序位于System.Data.OleDbSQLServer OLEDBSQLServer提供程序OleDbSqlOleDbSqlusingusingusingusingusing; SQLSERVER namespace{class{staticvoidMain({stringconnStr=“server=(local);InitialCatalog=students;userId=sa;password=1234”;SqlConnectionconn=newSqlConnection(connStr);conn.Open(); mand(mandText=“SelectID,sNamefromstudent”;SqlDataReaderreader=cmd.ExecuteReader();stringoutput;while(reader.Read())output=string.Format({0}\t }reader.Close();conn.Close();}}usingusingusingusing;connStr變量,用來(lái)存放連接SQLSERVER的數(shù)據(jù)庫(kù)連接字符串。stringconnStr=“server=(local);InitialCatalog=students;userId=sa;password=1234”;SqlConnectionconn=newSqlConnection(connStr);conn.Open(); mand(mandText=“SelectID,sNamefromSqlDataReaderreader=cmd.ExecuteReader( while(reader.Read(output=string.Format({0}\t } reader.Close();conn.Close(); 用OLEDB數(shù)據(jù)提供程序時(shí),要使用System.Data.OleDb空間的OleDbConnection對(duì)象,使用SQLServer數(shù)據(jù)提供
連接到SqlstringconnStr=“server=(local);InitialCatalog=students;userId=sa;password=1234”;SqlConnectionconn=newSqlConnection(connStr);conn.Open();SqlConnectionconn=newSqlConnection(“server=(local);InitialCatalog=students;userconn.Open(連接到Sql 接字符串賦值給Connection對(duì)象。如果不知道該對(duì)象是打開(kāi)stringconnStr=“server=(local);InitialstringconnStr=“DataSource=(local);InitialCatalog=students;userId=sa;password=1234”;InitialCatalog指明了連接使用的數(shù)據(jù)庫(kù),userID和password則分別指明了數(shù)據(jù)庫(kù)時(shí)使用的用戶名和密 stringconnStr=“DataSource=(local);InitialCatalog=students;IntegratedSecurity=SSPI”;SqlConnection由自己的方法,如前面使用過(guò)的OpenClosed()方法。
啟動(dòng),新建一個(gè)windows usingSystem.Data.Sql {SqlConnectionconn=newSqlConnection(id=sa;password=1234;initialCatalog=student;”;conn.Open();conn.Close();}catch(Exception} 連接OLEDB目前在網(wǎng)絡(luò)流行的小型數(shù)據(jù)庫(kù)access,就應(yīng)該使用OLEDBNET數(shù)據(jù)提供程序來(lái)數(shù)據(jù),該程序在System.Data.OleDb空間中使用OLEDB.NETSQLSERVER.NET數(shù)據(jù)提 Source=mydb.mdb;userid=;password=; 略,在實(shí)際項(xiàng)目中,DataSource還必須轉(zhuǎn)化為絕對(duì)路徑。連接OLEDBusingSystem.Data.OleDb;
連接OLEDB{OleDbConnectionconn=newOleDbConnection(stringconnStr="Provider= .Jet.OLEDB.4.0;DataSource=";conn.Open();conn.Close();MessageBox.Show("關(guān)閉成功");}catch(Exception} 括為CRUD-CreateReadUpdate和Delete。 類型為TableDirect時(shí),CommandText屬性為要 mand mand(象CommandText可以是從數(shù)據(jù)庫(kù)檢索數(shù)據(jù)的SQLSelect語(yǔ)句:stringCommandText=“select*fromstudent”; stringmandcmd=new mandcmd=newmand(ID,sName ExecuteScalar方法執(zhí)行返回單個(gè)值令,例如,想獲取數(shù)count(*)fromstudent。btnGetCount,以及l(fā)abel控件lblResult。stringcommandText=“selectcount(*)fromstringconnString=“DateSource=(local);InitialCatalog=students;userid=sa;password=1234”;SqlConnectionconn=newSqlConnection();mandcmd=new conn.Open();stringcount=cmd.ExecuteScalar().ToString();conn.Close();-1stringupdateQuery=“UPdatestudentSetsName=‘ SqlConnectionconn=newSqlConnection();mandcmd=new conn.Open();intRecordsAffected=cmd.ExecuteNonQuery();conn.Close(stringuserName=“ stringuserid=“200131500145”;stringupdateQuery=“UpdatestudentsName=‘”+userName+”’”+”WhereID=‘“+userid+”‘在SQLSERVER.NET UpdatestudentSetsName=@userNamewhereID=@userstringupdateQuery=“UpdatestudentSetsName=@userName”+”WhereID=@userid”;SqlConnectionconn=newSqlConnection(connectionString);mandcmd=new 對(duì)象。mand類提供了一個(gè)Parameters集合屬性,用以為命c(diǎn)md.Parameters.Add(“@userid”,userid); 在OLEDBNETOLEDB.NET并不支持指定參數(shù)的方法,但是可以在查詢中使用?來(lái)UpdatestudentSetsName=?Wheremandcmd=new cmd.Parameters.Add(“ID”,userid);數(shù),兩句代碼如果調(diào)換前后順序,則userid的值賦值給第一個(gè)參數(shù), boolCheckInfo({if(this.textbox1.Text.Trim(returnfalse;}elseif(this.textbox2.Text.Trim({MessageBox.Show(“ returnfalse;}returntrue;if(this.CheckInfo()){stringuserName=this.textbox2.Text.Trim(stringuserid=this.textbox1.Text.Trim(SqlConnectionconn=newSqlConnection(Catalog=student;userid=sa;password=1234”;stringupdateQuery=“updatestudentSetsName=‘”+userName+”‘“+”WhereID=‘”+userid+”mand conn.Open(int.ExecuteNonQuery();conn.Close();}if(this.CheckInfo()){stringuserName=this.textbox2.Text.Trim();stringuserid=this.textbox1.Text.Trim();SqlConnectionconn=newSqlConnection();Catalog=student;userid=sa;password=1234”;stringupdateQuery=“updatestudentSetsName=@userNameWhereID=@userid”;mand SqlParameter(“@userid”,userconn.Open(int.ExecuteNonQuery();conn.Close();}stringinsertQuery=“Insertintostudent ‘,’SqlConnectionconn=new ry,conn);conn.Open(intRecordsAffected=cmd.ExecuteNonQuery();conn.Close();stringdeleteQuery=“DeletefromstudentwhereSqlConnectionconn=newmandcmd=new conn.Open();intRecordsAffected=cmd.ExecuteNonQuery();conn.Close(); mandcmd=newSqlDataReaderreader=cmd.ExecuteReader(reader.Close( Item屬性是DataReader類的索引,總是基于0開(kāi)始編號(hào)的??僧?dāng)執(zhí)行完SQL(selectID,sNamefromstudent)查詢后使用objectID=reader[“ID”];objectID=reader[0];objectsName=reader[1];intID=(int)reader[0]; intstring (3)在Form1.cs中添加命名空間usingSy stringmessage=“OleDbConnectionconn=newOleDbConnection(); stringselectQuery=“selectID,sName,sGrade,s fromstudent”;mandcmd=new conn.Open(OleDbDataReader.ExecuteReader(CommandBehavior.CloseConnection);while(reader.read()){message+=“學(xué)號(hào):”+reader[0].ToString()+”“;message+=“姓名:”+reader[“sName”].ToString()+”“;message+=“班級(jí):”+reader.GetString(2)+”“;message+=“ “+reader.GetString(3)+”“;message+=“\n”;}reader.Close(stringmessage=“OleDbConnectionconn=newOleDbConnection(); stringselectQuery=“selectID,sName,sGrade,s fromstudent”;mandcmd=new conn.Open(OleDbDataReader.ExecuteReader(CommandBehavior.Cl
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 心電圖室獎(jiǎng)懲制度的制定意見(jiàn)
- 2025年度汽車維修廠汽車尾氣排放檢測(cè)與治理合同
- 金華浙江金華永康市古山鎮(zhèn)人民政府工作人員招聘筆試歷年參考題庫(kù)附帶答案詳解
- 金華2025年浙江金華浦江縣縣屬醫(yī)療衛(wèi)生單位招聘護(hù)理等專業(yè)人員16人筆試歷年參考題庫(kù)附帶答案詳解
- 浙江浙江省疾病預(yù)防控制中心招聘勞務(wù)派遣員工筆試歷年參考題庫(kù)附帶答案詳解
- 杭州2025年浙江杭州市教育局所屬事業(yè)單位招聘166人筆試歷年參考題庫(kù)附帶答案詳解
- 2025年中國(guó)雙層床架市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)一次性使用PE手套市場(chǎng)調(diào)查研究報(bào)告
- 2025年規(guī)則導(dǎo)線剝皮機(jī)項(xiàng)目可行性研究報(bào)告
- 2025年罐頭盒蠟燭項(xiàng)目可行性研究報(bào)告
- 營(yíng)銷管理方案中的定價(jià)策略與盈利模式
- 2024年西寧城市職業(yè)技術(shù)學(xué)院高職單招(英語(yǔ)/數(shù)學(xué)/語(yǔ)文)筆試歷年參考題庫(kù)含答案解析
- 2024年臨沂市高三一模(學(xué)業(yè)水平等級(jí)考試模擬試題)物理試卷
- 廣州獵德大橋三維曲面塔清水混凝土施工技術(shù)
- 我國(guó)糖尿病視網(wǎng)膜病變臨床診療指南2022解讀
- Python數(shù)據(jù)挖掘?qū)崙?zhàn)全套教學(xué)課件
- 高級(jí)茶藝師技能鑒定(協(xié)會(huì)版)備考題庫(kù)-下(多選、判斷題匯總)
- 特種設(shè)備作業(yè)人員體檢表(叉車)
- c30混凝土路面施工方案
- 加強(qiáng)師德師風(fēng)建設(shè)學(xué)校師德師風(fēng)警示教育講座培訓(xùn)課件
- 豬飼料購(gòu)銷合同書
評(píng)論
0/150
提交評(píng)論