C sharp - Insert Fecha en SQL

 
Vista:

Insert Fecha en SQL

Publicado por Ramiro Polverini (20 intervenciones) el 14/07/2005 00:38:44
Buenas.... Necesitaria que alguien me de una manito. Estoy tratando de hacer un INSERT en una database firebird con c#. Con Campos de tipo VARCHAR no tengo problema, grabo directamente los strings de c#. El tema es cuando quiero grabar un campo tipo DATE en la database ¿Como se hace el INSERT???
Yo lo estoy haciendo de esta manera y me da error en la conversion(la libreria de FireBird):

Conectar.ComandoSQL("INSERT INTO VEHICULOS (NROPATENTE,MARCA,MODELO,ANIO,VTVNRO,VTVVTO,RUTANRO,RUTAVTO,POLIZASEGNRO,GNCNRO,GNCVTO) VALUES ('"+this.Patente.Text+"','"+this.Marca.Text+ "','"+this.Modelo.Text+ "','"+this.Año.Text+ "','"+this.VTVNro.Text+ "','"+DateTime.Parse( this.VTVVto.Text).ToShortDateString()+"','"+ this.RUTANro.Text +"','"+DateTime.Parse( this.RutaVto.Text).ToShortDateString()+"','"+ this.Seguro.Text +"','"+ this.GNCNro.Text +"','"+DateTime.Parse( this.GNCVto.Text ).ToShortDateString()+"')");

Desde ya Gracias de antemano
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Insert Fecha en SQL

Publicado por Ramiro Polverini (20 intervenciones) el 14/07/2005 04:49:00
Me Contesto solo por si a alguien le sirve:

FbTransaction transaction = this.Connection.BeginTransaction();
DateTime dValue = DateTime.Parse("01.01.1999");

string sql = "insert into test (int_field, date_field) values (@int_field, @date_field)";

try
{
FbCommand cmd = new FbCommand(
sql,
this.Connection,
transaction);
cmd.Parameters.Add("@int_Field", FbDbType.Integer).Value = 20000;
cmd.Parameters.Add("@date_field", FbDbType.Date).Value = dValue;

int result = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
transaction.Commit();
}
Osea, se agrega con parameters.add el valor y el tipo, el cual es pasado a FireBird
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar