Пример #1
0
        /// <summary>
        /// 照SQL語法取得Table資料
        /// </summary>
        /// <param name="Schema"></param>
        /// <returns></returns>
        private DataTable GetDataTable(string Schema, params object[] Values)
        {
            DataTable Dt;
            DaoErrMsg Err = m_MSSQL.GetDataTable(Schema, out Dt, Values);

            if (Err.isError)
            {
                return(null);
            }

            return(Dt);
        }
Пример #2
0
        /// <summary>
        /// 連接MSSQL資料庫
        /// </summary>
        /// <returns></returns>
        private DaoErrMsg ConnectMSSQL(string ServerPath, string DbName, string DbID, string DbPW)
        {
            DaoErrMsg Err = new DaoErrMsg();

            if (m_MSSQL != null)
            {
                //表示已開啟過;//
                return(Err);
            }

            //建立資料庫連接字串
            ////注意:SQLExpress版本要寫成:「.\sqlexpress」
            //string strServerPath = Properties.Settings.Default.DB_SERVER_NAME;
            ////strServerPath = @"KEYNES-PC\EXPRESS";
            //string strDbName = Properties.Settings.Default.DB_NAME;
            //string strDbID = Properties.Settings.Default.DB_ID;
            //string strDbPW = Properties.Settings.Default.DB_PW;
            string strConnection = string.Format(@"server={0};database={1};uid={2};pwd={3}",
                                                 ServerPath,
                                                 DbName,
                                                 DbID,
                                                 DbPW);

            m_MSSQL = new DaoDbCommon(strConnection, new SqlConnection());

            Err = m_MSSQL.Connect();

            if (Err.isError)
            {
                System.Diagnostics.Debug.WriteLine(Err.ErrorMsg);
                m_MSSQL = null;
                return(Err);
            }

            DatabaseConnectedChange?.Invoke(true);

            return(Err);
        }