Ejemplo n.º 1
0
        private static void ExecuteNonQuery(string sql, string connectionString, DataBaseConnectionType connectionType)
        {
            connectionString = ConnectionString.FindConnectionString(connectionString);
            if (connectionType == DataBaseConnectionType.Auto ||
                connectionType == DataBaseConnectionType.Unknown)
            {
                connectionType = ConnectionType.FindConnectionType(connectionString);
            }

            if (connectionType == DataBaseConnectionType.Unknown)
            {
                throw new ApplicationException(
                          "Unable to automatically determine type of database from connection string. (ExecuteNonQuery)");
            }

            switch (connectionType)
            {
            case DataBaseConnectionType.SqlConnection:
                SqlConnectionQuery.ExecuteNonQuery(sql, connectionString);
                break;

            case DataBaseConnectionType.OleDB:
                OleDBQuery.ExecuteNonQuery(sql, connectionString);
                break;

            default:
                throw new ApplicationException("Unknown connection type.");
            }
        }
Ejemplo n.º 2
0
        private static object ExecuteScalar(string sql, string connectionString, DataBaseConnectionType connectionType)
        {
            connectionString = ConnectionString.FindConnectionString(connectionString);
            if (connectionType == DataBaseConnectionType.Auto || connectionType == DataBaseConnectionType.Unknown)
            {
                connectionType = ConnectionType.FindConnectionType(connectionString);
            }

            if (connectionType == DataBaseConnectionType.Unknown)
            {
                throw new GridException(
                          "Unable to automatically determine type of database from connection string (ExecuteScalar)" + connectionString);
            }

            switch (connectionType)
            {
            case DataBaseConnectionType.SqlConnection:
                return(SqlConnectionQuery.ExecuteScalar(sql, connectionString));

            case DataBaseConnectionType.OleDB:
                return(OleDBQuery.ExecuteScalar(sql, connectionString));

            default:
                throw new GridException("Unknown connection type.");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes a Transact-SQL statement and returns a WebGrid.Util.Query object.
        /// </summary>
        /// <param name="sql">The SQL statement</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="connectionType">Type of the connection.</param>
        /// <returns>
        /// WebGrid.Util.Query object containing the results from the executed SQL statement
        /// </returns>
        internal static Query ExecuteReader(string sql, string connectionString, DataBaseConnectionType connectionType)
        {
            connectionString = ConnectionString.FindConnectionString(connectionString);
            if (connectionType == DataBaseConnectionType.Auto ||
                connectionType == DataBaseConnectionType.Unknown)
            {
                connectionType = ConnectionType.FindConnectionType(connectionString);
            }

            if (connectionType == DataBaseConnectionType.Unknown)
            {
                throw new ApplicationException(
                          string.Format("Unable to automatically determine type of database from connection string. (ExecuteReader) ConnectionString: {0}", connectionString));
            }

            switch (connectionType)
            {
            case DataBaseConnectionType.SqlConnection:
                return(SqlConnectionQuery.ExecuteReader(sql, connectionString));

            case DataBaseConnectionType.OleDB:
                return(OleDBQuery.ExecuteReader(sql, connectionString));

            //    case DataBaseConnectionTypes.MySql:
            //        return MySqlQuery.ExecuteReader(sql, connectionString);
            default:
                throw new ApplicationException("Unknown connection type.");
            }
        }