Access数据连接

作者在 2007-08-11 00:03:00 发布以下内容

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Bookshop
{
    class Connection
    {
        OleDbConnection con;

        public OleDbConnection GetConnection()
        {
            try
            {
                string str = "Provider = Microsoft.JET.OLEDB.4.0;Data Source = {0}{1}; Jet OLEDB:Database Password =sh004";
                str = String.Format(str, System.AppDomain.CurrentDomain.BaseDirectory, "BookSell.mdb");
                con = new OleDbConnection();
                con.ConnectionString = str;
                con.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("请检查数据库。" + ex.ToString());
            }

            return con;
        }
    }   
}

C# | 阅读 1372 次
文章评论,共0条
游客请输入验证码
最新评论