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

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

c#操作Access(上)看到

CSDN上不斷兄弟姐妹提問關于

c#操作

Access

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

c#操作Access

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

Access數據庫的基礎知識,并提供一個相關的例程。ACCESS(MDB)數據庫,所以還只能使用 ADOX這個來自

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

table了),其中的

中插入數據(按行插入,如果需要插入多條請自己組織這個函數就insertArray 存儲的是一系列 Node,pictureNode 是PictureNode。viewplaincopytoclipboardprint新一行的數據(與插入類似)viewplaincopytoclipboardprint插入圖片數據 .viewplaincopytoclipboardprintalue=pic;();();returntrue;}catch(Exceptionerr){errinfo=;returnfalse;}}alue=pic;();();returntrue;}catch(Exceptionerr){errinfo=;returnfalse;}}修改mdb的一條數據.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實現(xiàn)數據庫增刪改查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實現(xiàn)增刪改查等功能 (Access版) 系列之五-查詢查詢記錄模塊設計與實現(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)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論