Example #1
0
 public string GenerarInsertInto(ObjetoInsert ins)
 {
     string devolver=null, into = null, values = null;
     for(int i= 0; i<ins.ValoresInsert.Count;i++)
     {
         into += ins.ValoresInsert[i].Into;
         values += ins.ValoresInsert[i].ValueComillas? "'"+ins.ValoresInsert[i].Value+"'":ins.ValoresInsert[i].Value;
         if (i != ins.ValoresInsert.Count - 1)
         {
             into += ",";
             values += ",";
         }
     }
     devolver = string.Format("INSERT INTO {0} ({1}) VALUES ({2});",ins.Tabla,into,values);
     return devolver;
 }
Example #2
0
 public override void Insertar(ObjetoInsert insert)
 {
     string consulta = GenerarInsertInto(insert);
     _command = new MySqlCommand(consulta, _connection);
     try
     {
         _connection.Open();
         _command.ExecuteNonQuery();
     }
     catch (MySqlException exc)
     {
         if (exc.Number == 2627)
             throw new Exception("Ya existe un elemento con este Id. Por favor cámbielo y vuelva a intentarlo");
         if (exc.Number == 1062)
         {
             //string m = exc.Message;
             //string a = m.Substring(m.IndexOf('\'')+1);
             //string valor = a.Remove(a.IndexOf('\''));
             //string c = a.Substring(a.IndexOf('\'')+1);
             //string d = c.Substring(c.IndexOf('\'')+1);
             //string campo = d.Remove(d.IndexOf('\''));
             string valor, campo;
             ObtenerValorCampoDuplicado(exc.Message, out valor, out campo);
             throw new BaseDatosEntradaDuplicadaException(valor, campo);
             //exc.Message.Substring(esc.me
         }
         else
         {
             throw new Exception("Mensaje: " + exc.Message + "\n\n" + "Consulta: " + consulta);
         }
     }
     finally
     {
         _connection.Close();
     }
 }
Example #3
0
 public abstract void Insertar(ObjetoInsert Insert);