




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
ADO(ActiveDataObjects)是 續(xù)技術(shù),提供對SQLSEVER等數(shù)據(jù)源的一致 (SQLSERVER\ACCESS\OLEDB等),ADO.NETDataSet是ADO.NET結(jié)構(gòu)的 元素是.NETFramawork 目前,.NETFramawork附帶了兩個數(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變量,用來存放連接SQLSERVER的數(shù)據(jù)庫連接字符串。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對象,使用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對象。如果不知道該對象是打開stringconnStr=“server=(local);InitialstringconnStr=“DataSource=(local);InitialCatalog=students;userId=sa;password=1234”;InitialCatalog指明了連接使用的數(shù)據(jù)庫,userID和password則分別指明了數(shù)據(jù)庫時(shí)使用的用戶名和密 stringconnStr=“DataSource=(local);InitialCatalog=students;IntegratedSecurity=SSPI”;SqlConnection由自己的方法,如前面使用過的OpenClosed()方法。
啟動,新建一個windows usingSystem.Data.Sql {SqlConnectionconn=newSqlConnection(id=sa;password=1234;initialCatalog=student;”;conn.Open();conn.Close();}catch(Exception} 連接OLEDB目前在網(wǎng)絡(luò)流行的小型數(shù)據(jù)庫access,就應(yīng)該使用OLEDBNET數(shù)據(jù)提供程序來數(shù)據(jù),該程序在System.Data.OleDb空間中使用OLEDB.NETSQLSERVER.NET數(shù)據(jù)提 Source=mydb.mdb;userid=;password=; 略,在實(shí)際項(xiàng)目中,DataSource還必須轉(zhuǎn)化為絕對路徑。連接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ù)庫檢索數(shù)據(jù)的SQLSelect語句:stringCommandText=“select*fromstudent”; stringmandcmd=new mandcmd=newmand(ID,sName ExecuteScalar方法執(zhí)行返回單個值令,例如,想獲取數(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 對象。mand類提供了一個Parameters集合屬性,用以為命c(diǎn)md.Parameters.Add(“@userid”,userid); 在OLEDBNETOLEDB.NET并不支持指定參數(shù)的方法,但是可以在查詢中使用?來UpdatestudentSetsName=?Wheremandcmd=new cmd.Parameters.Add(“ID”,userid);數(shù),兩句代碼如果調(diào)換前后順序,則userid的值賦值給第一個參數(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開始編號的??僧?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é)號:”+reader[0].ToString()+”“;message+=“姓名:”+reader[“sName”].ToString()+”“;message+=“班級:”+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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 電梯贈予合同7篇
- 小產(chǎn)權(quán)轉(zhuǎn)讓合同6篇
- 國際貿(mào)易之間合作合同
- 公司技術(shù)合作合同協(xié)議書
- 2025年中山貨運(yùn)資格證模擬考試題庫
- 2025年揚(yáng)州貨運(yùn)從業(yè)資格證模擬考試下載安裝
- 室內(nèi)裝修合同二5篇
- 的擔(dān)保借款合同7篇
- 觀看湖北消防119宣傳月節(jié)目心得感悟集合4篇
- 在民主生活會上的點(diǎn)評講話模板
- 新質(zhì)生產(chǎn)力與產(chǎn)品創(chuàng)新
- 能力素質(zhì)模型的正確打開方式(分享)
- 2024年河北省公務(wù)員錄用考試《行測》真題及答案解析
- 安保服務(wù)行業(yè)市場調(diào)研分析報(bào)告
- 吉林大學(xué)《微積分AⅠ》2021-2022學(xué)年第一學(xué)期期末試卷
- 現(xiàn)代家政導(dǎo)論-課件 6.1.1認(rèn)識道德與職業(yè)道德
- 《建筑工程施工許可管理辦法》2021年9月28日修訂
- 普通話培訓(xùn)教案1(共5篇)
- 大慶醫(yī)學(xué)高等專科學(xué)校單招參考試題庫(含答案)
- 綿陽市三臺縣鄉(xiāng)鎮(zhèn)地圖矢量可編輯課件行政區(qū)劃邊界高清(四川省)
- 新疆城市綠地養(yǎng)護(hù)管理標(biāo)準(zhǔn)
評論
0/150
提交評論