c#操作access數(shù)據(jù)庫編程1_第1頁
c#操作access數(shù)據(jù)庫編程1_第2頁
c#操作access數(shù)據(jù)庫編程1_第3頁
c#操作access數(shù)據(jù)庫編程1_第4頁
c#操作access數(shù)據(jù)庫編程1_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

c#操作Access(上)看到

CSDN上不斷兄弟姐妹提問關(guān)于

c#操作

Access

的問題,于是本人利用閑暇將

c#操作Access

的方法加以總結(jié),主要解決的問題有:創(chuàng)建mdb創(chuàng)建table讀取table 內(nèi)容查詢table 中的內(nèi)容向table中插入數(shù)據(jù)刪除table中的記錄向table中插入照片讀取table中的照片等。另:本人水平有限,不當(dāng)之處還請斧正。廢話少說,開始正題。文介紹C#訪問操作程方式創(chuàng)建全新的

Access數(shù)據(jù)庫的基礎(chǔ)知識,并提供一個(gè)相關(guān)的例程。ACCESS(MDB)數(shù)據(jù)庫,所以還只能使用 ADOX這個(gè)來自

C#的還不能通過編COM的鏈接庫來操作。主要知識點(diǎn)如下:usingusing;連接字符串:StringconnectionString="Provider=Source=";建立連接:OleDbConnectionconnection=newOleDbConnection(connectionString);使用OleDbCommand類來執(zhí)行Sql語句:OleDbCommandcmd=newOleDbCommand(sql,connection);();();創(chuàng)建mdb庫,例程如下:需要注意的是:參數(shù) mdbPath是mdb的完整路徑(不包含表的名稱) 。例如:viewplaincopytoclipboardprint建具體的表,例程如下:通常一個(gè) mdb的可以包含 n個(gè)表。下面的程序主要是創(chuàng)建一個(gè) table。viewplaincopytoclipboardprintoString();alue=false;500);}oString();alue=false;500);}取mdb內(nèi)容(完全讀?。?,例程如下:本例程返回的是一個(gè)DataTable,如需其他格式可以自行轉(zhuǎn)換。viewplaincopytoclipboardprintoString();}}oString();}}取mdb內(nèi)容(按列讀?。倘缦拢篶olumns數(shù)組存儲的是你要查詢的列名稱(必須確保 mdb表中存在你要的列)viewplaincopytoclipboardprintoString()+",";}strColumn=(',');"select"+strColumn+"from"+tableName;oString();}}oString()+",";}strColumn=(',');="select"+strColumn+"from"+tableName;oString();}}ok

table了),其中的

中插入數(shù)據(jù)(按行插入,如果需要插入多條請自己組織這個(gè)函數(shù)就insertArray 存儲的是一系列 Node,pictureNode 是PictureNode。viewplaincopytoclipboardprint新一行的數(shù)據(jù)(與插入類似)viewplaincopytoclipboardprint插入圖片數(shù)據(jù) .viewplaincopytoclipboardprintalue=pic;();();returntrue;}catch(Exceptionerr){errinfo=;returnfalse;}}alue=pic;();();returntrue;}catch(Exceptionerr){errinfo=;returnfalse;}}修改mdb的一條數(shù)據(jù).viewplaincopytoclipboardprintmdb中獲得照片viewplaincopytoclipboardprintdb";privatedataGrid1;privateDataSetds=null;publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){();con=newOleDbConnection(sqlstring);getData();oString();=dr[1].ToString();}}catch(Exceptionex){;}finally{();}}privatevoidbutton1_Click(objectsender,EventArgse){Form2f=newForm2;();}}}在C#中使用控件DataGridView實(shí)現(xiàn)數(shù)據(jù)庫增刪改查usingSystem;usingusing;using;usingusing;using;usingDataSource{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privateDataSetds=newDataSet();privateSqlConnectionconn=null;privateSqlDataAdapterda=null;privateconststringDRIVER="server=.;database=northwind;uid=sa;pwd=sa";privateconststringsql_select="select*fromregion";privatevoidForm1_Load(objectsender,EventArgse){conn=newSqlConnection(DRIVER);da=newSqlDataAdapter(sql_select,conn);(ds,"table");=["table"].DefaultView;}privateboolBtnInsert()ows[intcount=(ds);boolresult=count>0true:false;returnresult;}privatevoidbutton2_Click(objectsender,EventArgse){if())..;oString());}if(mcount>0){elected=true;=[].Cells[];}}}ndex; ells[j].()+",";}}ResumeAddOrUpdateresumeAdd=newResumeAddOrUpdate(str,this);("Update");=; quals("save")){true;false;}elseif().Equals("update")){=false;true;false;}}quals("

男")){=true;}elseif(content[1].Equals("{

女"))=true;}=content[2].ToString();=content[3].ToString();=content[4].ToString();=content[5].ToString();=content[6].ToString();=content[7].ToString();=content[8].ToString();=content[9].ToString();=content[10].ToString();stringstrPictrueBox=getStrOfPictureBoxpg");}}ndex; ells[0].().Trim();elected=true;=[].Cells[];}}}C#WinForm實(shí)現(xiàn)增刪改查等功能 (Access版) 系列之五-查詢查詢記錄模塊設(shè)計(jì)與實(shí)現(xiàn)oString().Equals("0")&&reader[0].ToString()!=""&&reader[0].ToString()!=null){strpictrue=reader[0].ToString();}else{strpictrue=+"\\Image\\";}}/*DataTabledt=newDataTable();OleDbDataAdapteroda=newOleDbDataAdapter(sqlText,conn);(dt);dt;*/}catch(Exceptionex){());}finally{();}returnstrpictrue;}打開對話框,選擇圖片,上傳圖片|*.*|jpgfiles(*.jpg)|*.jpg";"jpgfiles(*.jpg)|*.jpg";DialogResultdr=();if(dr=={stringimage=;stringpicpath=;DateTimedt1=newDateTime(1970,1,1);TimeSpants=-dt1;

溫馨提示

  • 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論