C# ACCESS应用

ACCESS是微软的数据库,为了用C#控制,简单几句话先记下来。

string conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\Documents\apx.accdb";                   
            try
            {
                using (OleDbConnection con = new OleDbConnection(conStr))
                {
                    con.Open();
                    //创建适配对象
                    OleDbDataAdapter OleDbdap = new OleDbDataAdapter("select * from apx_ctrInf", con);
                    DataSet ds = new DataSet();
                    DataTable dt = new DataTable(); //新建表对象
                    OleDbdap.Fill(ds, "apx_ctrInf");//用适配对象填充表对象
                    foreach (DataRow item in dt.Rows)
                    {
                        Console.WriteLine(item[0] + " | " + item[1]);
                    }
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

猜你喜欢

转载自blog.csdn.net/qq_36196748/article/details/82019341
今日推荐