`
yaoweinan
  • 浏览: 134299 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

C# 连接数据库

阅读更多

using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{

    /// <summary>
    /// condb 的摘要说明
    /// </summary>
    public class DBHelper
    {
        private OleDbConnection conn;
        private OleDbDataAdapter oda = new OleDbDataAdapter();
        private OleDbCommand cmd;
        private DataSet myds = new DataSet();
        public DBHelper()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
            conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"/db/dbtest.mdb");
        }
        public DataSet getDS(string strSQL)
        {
            myds = new DataSet();
            oda = new OleDbDataAdapter(strSQL, conn);
            oda.Fill(myds);
            return myds;
        }

        public DataSet getDS2(string strSQL, int si, int mi)
        {
            conn.Open();
            myds = new DataSet();
            oda = new OleDbDataAdapter(strSQL, conn);
            oda.Fill(myds, si, mi, "tab1");
            conn.Close();
            return myds;

        }

        public bool setDS(string strSQL)
        {
            conn.Open();
            cmd = new OleDbCommand(strSQL, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            return true;
        }
    }

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics