How to connect to a MS Access file (mdb) using C#?

前端 未结 6 813
迷失自我
迷失自我 2020-11-27 21:24

I\'m trying to connect to a mdb file and I understand that I would need Microsoft.OLEDB.JET.4.0 data provider. Unfortunately, I do not have it installed on the

6条回答
  •  忘掉有多难
    2020-11-27 21:44

    What Access File extension or you using? The Jet OLEDB or the Ace OLEDB. If your Access DB is .mdb (aka Jet Oledb)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Oledb
    
    namespace MembershipInformationSystem.Helpers
    {
        public class dbs
        {
            private String connectionString;
            private String OleDBProvider = "Microsoft.JET.OLEDB.4.0"; \\if ACE Microsoft.ACE.OLEDB.12.0
            private String OleDBDataSource = "C:\\yourdb.mdb";
            private String OleDBPassword = "infosys";
            private String PersistSecurityInfo = "False";
    
            public dbs()
            {
    
            }
    
            public dbs(String connectionString)
            {
                this.connectionString = connectionString;
            }
    
            public String konek()
            {
                connectionString = "Provider=" + OleDBProvider + ";Data Source=" + OleDBDataSource + ";JET OLEDB:Database Password=" + OleDBPassword + ";Persist Security Info=" + PersistSecurityInfo + "";
                return connectionString;
            }
        }
    }
    

提交回复
热议问题