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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。