By entering the data in the program in date time format for the database, by accepting it (image 1)
shows me the following error (image 2)
public bool insertar(string sql)
{
cn.Open();
comando = new SqlCommand(sql, cn);
int i = comando.ExecuteNonQuery();
cn.Close();
if (i > 0)
{
return true;
}
else
{ return false; }
}
I put the same time format as it has and asks for the database (image 3).
private void boton_promocion_Click(object sender, EventArgs e)
{
fecha_inicio.Format = DateTimePickerFormat.Custom;
fecha_inicio.CustomFormat = "dd/MM/yyyy hh:mm:ss tt";
fecha_fin.Format = DateTimePickerFormat.Custom;
fecha_fin.CustomFormat = "dd/MM/yyyy hh:mm:ss tt";
int activo;
if (radio_promociones.Checked)
{
activo = 1;
}
else
{
activo = 0;
}
string registrar_usuario = "insert into tb_promociones(Status, Nombre, Fecha_inicio, Fecha_fin, Descuento, fk_platillos) values ('" + activo + "','" + this.texto_nombrePlatillo.Text + "' , '" + this.fecha_inicio.Text + "','" + this.fecha_fin.Text + "', '" + this.texto_descuento.Text + "', '" + this.combo_platillos.SelectedValue + "')";
if (obDatos.insertar(registrar_usuario))
{
MessageBox.Show("Se ha registrado a Promocion Correctamente");
}
else
{
MessageBox.Show("Error al Insertar, Consulte al Administrador del Sistema");
}
}
CREATE TABLE [dbo].[tb_promociones] ( [Id] INT IDENTITY (1, 1) NOT NULL, [Status] BIT NULL, [Nombre] VARCHAR (50) NULL, [Fecha_inicio] DATETIME NULL, [Fecha_fin] DATETIME NULL, [Descuento] VARCHAR (50) NULL, [fk_platillos] INT NULL, PRIMARY KEY CLUSTERED ([Id] ASC)
insert into tb_promociones(Status, Nombre, Fecha_inicio, Fecha_fin, Descuento, fk_platillos) values ('1','pollo' , '28/05/2018 02:10:02 a. m.','29/05/2018 02:10:02 a. m.', '20', '')