c#连接access数据库

1、数据来源

       从sql server中导出,在导出选择目标服务器时,要选择microsoft jet database engine,否则数据会无法读出

2、数据库连接

                   OleDbConnection,OleDbCommand,OleDbDataAdapter,

       如果是在控制台中,可以利用OleDbDataReader。

3、典型代码

                   string apppath = System.Windows.Forms.Application.StartupPath //获取整个文件路径名

                   apppath += @"\student1.mdb";

                   string strCon = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " +apppath;

                   OleDbConnection oleConn = new OleDbConnection(strCon);

            try
            {
                oleConn.Open();
                string strQuery = "select * from student_scyx ";
                OleDbDataAdapter oleda = new OleDbDataAdapter(strQuery, oleConn);
                oleda.Fill(ds, "DataStudent");
                return ds;
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.Message.ToString());
                throw (ee);
            }
            finally
            {
                oleConn.Close();
            }

4、界面中方法调用。


 

  

你可能感兴趣的:(C#)