El post es para solicitar su ayuda.
El problema que tengo es que en el siguiente código trato de insertar los datos a la base de datos:
Código:
Pero me envia un error el cual dice "Conversion failed when converting datetime from character string"string sql3 = " INSERT INTO CustodyValue.dbo.[Value] " + "(LocationId, ValueTypeId, StatusId, CostCenterId, " + " RegistrationDate, UpdateUserId, UpdateDate)" + " VALUES " + " ( '" + valor2 + "', '1', '4', '" + valor1 + "', " + " '"+ hoy2 +"', '1','"+ hoy2 +"' ) "; SqlCommand cmd1 = new SqlCommand(sql3, con2); cmd1.ExecuteNonQuery();
El campo valor2 es un campo string
El campo valor1 es un campo int
El campo hoy es un campo date time el cual obtengo de la siguiente forma:
Código:
Los campos que tiene la tabla CustodyValue.dbo.[Value] son ValueId, LocationId, ValueTypeId, StatusId, CostCenterId, RegistrationDate, UpdateUserId, UpdateDate, que por cierto el ValueId es identity y llave primaria.private DateTime diahoy = DateTime.Today; string hoy2 = diahoy.ToUniversalTime().ToString("u");
Que debo hacer para corregir el error o donde me pueden proporcionar un link para leer.
Por cierto utilizo C# 2008 y SQL Server 2005.
De antemano gracias por la ayuda y disculpas por quitarles su valioso tiempo.