I have a Datetimpiker but from this I only want to capture the time, in the format I put the time property and it stays like this
bd fields
That's how I needed it, those two fields are in the database as time type, but since the application keeps saving them as datetime, it's not enough just to change the format property to time?
How can I save the time from the application and when it is already in the database capture the time and show it to me as it is in the database
private void BtnGuardar_Click(object sender, EventArgs e)
{
if (operacion == "Insertar")
{
objetask.FInicio1 = Convert.ToDateTime(dateHInicio.Value);
objetask.HFin1 = Convert.ToDateTime(dateFin.Value);
objetask.Notas1 = txtNotas.Text;
objetask.InsertarActividad();
MessageBox.Show("Insertado correctamente");
this.Close();
}
else if (operacion == "Editar")
{
objetask.HInicio1 = Convert.ToDateTime(dateHInicio.Value);
objetask.HFin1 = Convert.ToDateTime(dateHFin.Value);
objetask.Notas1 = txtNotas.Text;
objetask.ActualizarActividad();
MessageBox.Show("Se edito correctamente");
this.Close();
}
}
exception
public void InsertarActividad()
{
using (var connection = GetConnection())
{
connection.Open();
using (var command = new SqlCommand())
{
command.Connection = connection;
command.CommandText = "InsertarActividad";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@DocRefe", DocRefe);
command.Parameters.AddWithValue("@NomActivi", NomActivi);
command.Parameters.AddWithValue("@CodTarea", CodTarea);
command.Parameters.AddWithValue("@codtipo", CodTipo);
command.Parameters.AddWithValue("@codprio", CodPrio);
command.Parameters.AddWithValue("@codresp", CodResp);
command.Parameters.AddWithValue("@codestad", CodEstad);
command.Parameters.AddWithValue("@fcreacion", FCreacion);
command.Parameters.AddWithValue("@finicio", FInicio);
command.Parameters.AddWithValue("@ffin", FFin);
command.Parameters.AddWithValue("@HInicio", HInicio);
command.Parameters.AddWithValue("@HFin", HFin);
command.Parameters.AddWithValue("@CodComplet", CodComplet);
command.Parameters.AddWithValue("@Notas", Notas);
command.ExecuteNonQuery();
command.Parameters.Clear();
}
}
}
I don't know why it tells me that the error comes from bd
The problem is that you are taking a date from
DateTimePicker
which it is not valid because you never allow its selection, you are only defining the time, that is why the date that you pass as a parameter is invalid and the parameter rejects it.If we analyze the types of parameters
Date and Time Date
You will notice that you must assign a
TimeSpan
and not aDateTime
Using the you
TimeOfDay
will get the type of data fortime
which you must send in the parameterCould you test if it works simpler with him