コード例 #1
0
        public int ExecuteNonQuery(string sqlText)
        {
            if (DBStatus != DBStatusENum.Opening)
            {
                return(-1);
            }
            int iRecordsAffected = -1;

            try
            {
                switch (Config.ServerType)
                {
                case DbServerType.SqlServer:
                    if (SqlExecute == null)
                    {
                        SqlExecute = new DbExecute <SqlConnection, SqlCommand, SqlDataAdapter, SqlDataReader>(Config.ConnectionString);
                    }
                    iRecordsAffected = SqlExecute.ExecuteNonQuery(sqlText);
                    break;

                case DbServerType.SqlServerCe:
                    if (SqlCeExecute == null)
                    {
                        SqlCeExecute = new DbExecute <SqlCeConnection, SqlCeCommand, SqlCeDataAdapter, SqlCeDataReader>(Config.ConnectionString);
                    }
                    iRecordsAffected = SqlCeExecute.ExecuteNonQuery(sqlText);
                    break;

                case DbServerType.MySql:
                    if (MySqlExecute == null)
                    {
                        MySqlExecute = new DbExecute <MySqlConnection, MySqlCommand, MySqlDataAdapter, MySqlDataReader>(Config.ConnectionString);
                    }
                    iRecordsAffected = MySqlExecute.ExecuteNonQuery(sqlText);
                    break;

                case DbServerType.Oracle:
                    if (OracleExecute == null)
                    {
                        OracleExecute = new DbExecute <OracleConnection, OracleCommand, OracleDataAdapter, OracleDataReader>(Config.ConnectionString);
                    }
                    iRecordsAffected = OracleExecute.ExecuteNonQuery(sqlText);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw (new Exception(ex.Message));
            }
            finally
            {
            }
            return(iRecordsAffected);
        }
コード例 #2
0
        public bool Open()
        {
            if (DBStatus == DBStatusENum.Opening)
            {
                return(true);
            }

            bool bSuccessOpened = false;

            try
            {
                switch (Config.ServerType)
                {
                case DbServerType.SqlServer:
                    if (SqlExecute == null)
                    {
                        SqlExecute = new DbExecute <SqlConnection, SqlCommand, SqlDataAdapter, SqlDataReader>();
                    }
                    SqlExecute.dbConnection.ConnectionString = Config.ConnectionString;
                    SqlExecute.dbConnection.Open();
                    bSuccessOpened = true;
                    break;

                case DbServerType.SqlServerCe:
                    if (SqlCeExecute == null)
                    {
                        SqlCeExecute = new DbExecute <SqlCeConnection, SqlCeCommand, SqlCeDataAdapter, SqlCeDataReader>();
                    }
                    SqlCeExecute.dbConnection.ConnectionString = Config.ConnectionString;
                    SqlCeExecute.dbConnection.Open();
                    bSuccessOpened = true;
                    break;

                case DbServerType.MySql:
                    if (MySqlExecute == null)
                    {
                        MySqlExecute = new DbExecute <MySqlConnection, MySqlCommand, MySqlDataAdapter, MySqlDataReader>();
                    }
                    MySqlExecute.dbConnection.ConnectionString = Config.ConnectionString;
                    MySqlExecute.dbConnection.Open();
                    bSuccessOpened = true;
                    break;

                case DbServerType.Oracle:
                    if (OracleExecute == null)
                    {
                        OracleExecute = new DbExecute <OracleConnection, OracleCommand, OracleDataAdapter, OracleDataReader>();
                    }
                    OracleExecute.dbConnection.ConnectionString = Config.ConnectionString;
                    OracleExecute.dbConnection.Open();
                    bSuccessOpened = true;
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw (new Exception(ex.Message));
            }
            finally
            {
            }
            return(bSuccessOpened);
        }
コード例 #3
0
        public bool ExecuteDataSet(string sqlText)
        {
            if (DBStatus != DBStatusENum.Opening)
            {
                return(false);
            }
            bool bSuccessExecuted = false;

            try
            {
                switch (Config.ServerType)
                {
                case DbServerType.SqlServer:
                    if (SqlExecute == null)
                    {
                        SqlExecute = new DbExecute <SqlConnection, SqlCommand, SqlDataAdapter, SqlDataReader>(Config.ConnectionString);
                    }
                    bSuccessExecuted = SqlExecute.ExecuteDataSet(sqlText);
                    if (bSuccessExecuted)
                    {
                        dataSet = SqlExecute.dataSet;
                    }
                    break;

                case DbServerType.SqlServerCe:
                    if (SqlCeExecute == null)
                    {
                        SqlCeExecute = new DbExecute <SqlCeConnection, SqlCeCommand, SqlCeDataAdapter, SqlCeDataReader>(Config.ConnectionString);
                    }
                    bSuccessExecuted = SqlCeExecute.ExecuteDataSet(sqlText);
                    if (bSuccessExecuted)
                    {
                        dataSet = SqlCeExecute.dataSet;
                    }
                    break;

                case DbServerType.MySql:
                    if (MySqlExecute == null)
                    {
                        MySqlExecute = new DbExecute <MySqlConnection, MySqlCommand, MySqlDataAdapter, MySqlDataReader>(Config.ConnectionString);
                    }
                    bSuccessExecuted = MySqlExecute.ExecuteDataSet(sqlText);
                    if (bSuccessExecuted)
                    {
                        dataSet = MySqlExecute.dataSet;
                    }
                    break;

                case DbServerType.Oracle:
                    if (OracleExecute == null)
                    {
                        OracleExecute = new DbExecute <OracleConnection, OracleCommand, OracleDataAdapter, OracleDataReader>(Config.ConnectionString);
                    }
                    bSuccessExecuted = OracleExecute.ExecuteDataSet(sqlText);
                    if (bSuccessExecuted)
                    {
                        dataSet = OracleExecute.dataSet;
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw (new Exception(ex.Message));
            }
            finally
            {
            }
            return(bSuccessExecuted);
        }