您好,登錄后才能下訂單哦!
1、OleDbDataReader用于從數據庫中讀取數據,參考代碼如下:
OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = @"Provider=microsoft.ace.oledb.12.0;Data Source=|DataDirectory|湖州工廠故障現象及原因數據庫.accdb;"; //查找故障現象表中有幾行,用于下面定義數組大小用 OleDbCommand com = new OleDbCommand("SELECT COUNT(故障現象代碼) AS NUM FROM 故障現象", conn); conn.Open(); OleDbDataReader drNew = com.ExecuteReader(); drNew.Read(); int F_rows = int.Parse(drNew["NUM"].ToString()); drNew.Close(); conn.Close();
2、OleDbDataAdapter用于鏈接數據庫,供DataSet使用,代碼如下:
OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = @"Provider=microsoft.ace.oledb.12.0;Data Source=|DataDirectory|湖州工廠故障現象及原因數據庫.accdb;"; //獲得故障現象表中的故障現象列表 OleDbDataAdapter Fname_Adapter = new OleDbDataAdapter("select 故障現象 from 故障現象", conn); DataSet Fname_table = new DataSet(); Fname_Adapter.Fill(Fname_table, "故障現象"); int Fname_sum = Fname_table.Tables["故障現象"].Rows.Count; string[] Fname = new string[Fname_sum]; for (int i = 0; i < Fname_table.Tables["故障現象"].Rows.Count;i++ ) { Fname[i] = (string)Fname_table.Tables["故障現象"].Rows[i]["故障現象"]; } Fname_table.Dispose(); int[] F_times = new int[Fname_sum]; //獲取查詢記錄中Fxxx的原始數據(這個數據有些是重復的,要對其進行處理)。 OleDbDataAdapter Fxxx_Adapter = new OleDbDataAdapter("select 故障現象 from 故障記錄", conn); DataSet Fxxx_table = new DataSet(); Fxxx_Adapter.Fill(Fxxx_table, "故障記錄"); //string iii = (string)Fxxx_table.Tables["故障記錄"].Rows[2]["故障現象"]; 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]["故障現象"]; } for (int j = 0; j < F_contents_sum; j++) { for(int k=0;k<Fname_sum;k++) { if (F_contents[j] == Fname[k]) F_times[k]++; } } Fxxx_table.Dispose();
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。