Example #1
0
 public int Delete(GenericDatabase db, String conditions)
 {
     string sql = "DELETE FROM " + TableName + " WHERE " + conditions;
     DbCommand dbCommand = db.GetOpenedConnection().CreateCommand();
     dbCommand.CommandText = sql;
     return dbCommand.ExecuteNonQuery();
 }
Example #2
0
 public DataTable GetFields(GenericDatabase db, string columns, string condetions = null)
 {
     DbCommand dbCommand = db.GetOpenedConnection().CreateCommand();
     dbCommand.CommandText = "SELECT " + columns + " FROM " + TableName;
     if (condetions != null)
     {
         dbCommand.CommandText += " WHERE " + condetions;
     }
     return GetDataTableFromCommand(dbCommand);
 }
Example #3
0
 public bool LoadWithPrimaryKey(GenericDatabase db, object primaryKeyValue)
 {
     DbCommand dbCommand = db.GetOpenedConnection().CreateCommand();
     dbCommand.CommandText = "SELECT * FROM " + TableName + " WHERE " + PrimaryKey.Name + " = " + db.GetAsParameterName(PrimaryKey.Name);
     dbCommand.Parameters.Add(db.GetDBCellAsDBParameter(dbCommand, new DBCell(PrimaryKey.Name, PrimaryKey.Type, primaryKeyValue)));
     return FillObjectWithDataReader(dbCommand);
 }
Example #4
0
 public bool Load(GenericDatabase db, string conditions)
 {
     DbCommand dbCommand = db.GetOpenedConnection().CreateCommand();
     dbCommand.CommandText = "SELECT * FROM " + TableName + " WHERE " + conditions;
     return FillObjectWithDataReader(dbCommand);
 }
Example #5
0
 public int Insert(GenericDatabase db)
 {
     DbCommand dbCommand = GetInsertCommand(db, db.GetOpenedConnection(), TableName, Values);
     return dbCommand.ExecuteNonQuery();
 }
Example #6
0
 private bool isValueExistsWithColumns(GenericDatabase db, String[] keyNames)
 {
     bool exists = false;
     if (keyNames == null)
     {
         throw new NullReferenceException();
     }
     else
     {
         if ((keyNames.Length <= 0) || (keyNames.Length > Values.Length))
         {
             throw new ArgumentException();
         }
         else
         {
             String sql = "Select TOP 1 * from " + TableName + " where ";
             DbCommand cmd = db.GetOpenedConnection().CreateCommand();
             for (int i = 0; i < keyNames.Length; i++)
             {
                 DBCell cell = this[keyNames[i]];
                 sql += " " + keyNames[i] + " = " + db.GetAsParameterName(keyNames[i]) + " and ";
                 cmd.Parameters.Add(db.GetDBCellAsDBParameter(cmd, cell));
             }
             sql += " 1=1";
             cmd.CommandText = sql;
             exists = (GetDataTableFromCommand(cmd).Rows.Count > 0);
         }
     }
     return exists;
 }
Example #7
0
 public int Update(GenericDatabase db, String conditions)
 {
     DbCommand dbCommand = GetUpdateCommand(db, db.GetOpenedConnection(), TableName, Values);
     if (conditions != null)
     {
         dbCommand.CommandText += " WHERE " + conditions;
     }
     return dbCommand.ExecuteNonQuery();
 }