1、OleDbDataReader用于從數(shù)據(jù)庫(kù)中讀取數(shù)據(jù),參考代碼如下:
成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的黑河網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = @"Provider=microsoft.ace.oledb.12.0;Data Source=|DataDirectory|湖州工廠故障現(xiàn)象及原因數(shù)據(jù)庫(kù).accdb;"; //查找故障現(xiàn)象表中有幾行,用于下面定義數(shù)組大小用 OleDbCommand com = new OleDbCommand("SELECT COUNT(故障現(xiàn)象代碼) AS NUM FROM 故障現(xiàn)象", conn); conn.Open(); OleDbDataReader drNew = com.ExecuteReader(); drNew.Read(); int F_rows = int.Parse(drNew["NUM"].ToString()); drNew.Close(); conn.Close();
2、OleDbDataAdapter用于鏈接數(shù)據(jù)庫(kù),供DataSet使用,代碼如下:
OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = @"Provider=microsoft.ace.oledb.12.0;Data Source=|DataDirectory|湖州工廠故障現(xiàn)象及原因數(shù)據(jù)庫(kù).accdb;"; //獲得故障現(xiàn)象表中的故障現(xiàn)象列表 OleDbDataAdapter Fname_Adapter = new OleDbDataAdapter("select 故障現(xiàn)象 from 故障現(xiàn)象", conn); DataSet Fname_table = new DataSet(); Fname_Adapter.Fill(Fname_table, "故障現(xiàn)象"); int Fname_sum = Fname_table.Tables["故障現(xiàn)象"].Rows.Count; string[] Fname = new string[Fname_sum]; for (int i = 0; i < Fname_table.Tables["故障現(xiàn)象"].Rows.Count;i++ ) { Fname[i] = (string)Fname_table.Tables["故障現(xiàn)象"].Rows[i]["故障現(xiàn)象"]; } Fname_table.Dispose(); int[] F_times = new int[Fname_sum]; //獲取查詢記錄中Fxxx的原始數(shù)據(jù)(這個(gè)數(shù)據(jù)有些是重復(fù)的,要對(duì)其進(jìn)行處理)。 OleDbDataAdapter Fxxx_Adapter = new OleDbDataAdapter("select 故障現(xiàn)象 from 故障記錄", conn); DataSet Fxxx_table = new DataSet(); Fxxx_Adapter.Fill(Fxxx_table, "故障記錄"); //string iii = (string)Fxxx_table.Tables["故障記錄"].Rows[2]["故障現(xiàn)象"]; int F_contents_sum = Fxxx_table.Tables["故障記錄"].Rows.Count; //有幾條故障記錄 string[] F_contents = new string[F_contents_sum]; for (int j = 0; j < F_contents_sum; j++) { F_contents[j] = (string)Fxxx_table.Tables["故障記錄"].Rows[j]["故障現(xiàn)象"]; } for (int j = 0; j < F_contents_sum; j++) { for(int k=0;k
分享題目:OleDbDataReader、OleDbDataAdapter、DataSet的使用方法
當(dāng)前鏈接:http://weahome.cn/article/peigsd.html