예제 #1
0
        /// <summary>
        /// 更新连接字符串信息
        /// </summary>
        private void UpdateDataBaseAccessInfo()
        {
            switch (databasetype)
            {
            case "sqlserver":
                if (!string.IsNullOrEmpty(server))
                {
                    connectiontext = "server=" + server + @";database=" + databasename + @";user id=" + userid + @";pwd=" + password + ";";
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new SqlServer(connectiontext);
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new SqlServer(connectiontext);
                    }
                }
                break;

            case "access":
                if (!string.IsNullOrWhiteSpace(databasefile))
                {
                    //conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + databasefile;
                    connectiontext = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + databasefile;
                    //conStr = "Provider=Microsoft.ACE.OLEDB.12.0;data source='" + databasefile + "'";
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new Access(connectiontext);
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new Access(connectiontext);
                    }
                }
                break;

            case "mysql":
                if (!string.IsNullOrWhiteSpace(server))
                {
                    connectiontext = "server=" + server + @";database=" + databasename + @";uid=" + userid + @";pwd=" + password + ";";
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new MySQL(connectiontext);
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new MySQL(connectiontext);
                    }
                }

                break;

            case "excel":
                if (!string.IsNullOrWhiteSpace(databasefile))
                {
                    connectiontext = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + databasefile;
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new Excel(connectiontext);
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new Excel(connectiontext);
                    }
                }
                break;

            case "oracle":
                if (!string.IsNullOrWhiteSpace(server))
                {
                    connectiontext = "Driver={Microsoft ODBC for Oracle};Server=" + server + ";Uid=" + userid + ";Pwd=" + password + ";";
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new Oracle(connectiontext);
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(connectiontext))
                    {
                        this.databaseaccess = new Oracle(connectiontext);
                    }
                }
                break;
            }
        }