1

Tengo el siguiente formulario

introducir la descripción de la imagen aquí

Al guardar los datos guarda todo bien pero la hora inicio y la hora fin no guarda la hora ingresada por el usuario si no que en los dos campos guarda la hora 3:40:00 la que esta ahí en el formulario mas no la que yo modifico es decir así ponga que son las 8:30:00 el me guarda las 3:40:00

Código

 private void BtnGuardar_Click(object sender, EventArgs e)
        {
            if (operacion == "Insertar")
            {
                objetask.DocRefeA1 = txtReferencia.Text;
                objetask.NomActivi1 = txtActividad.Text;
                objetask.CodTareas1 = Convert.ToInt32(cmbTarea.SelectedValue);
                objetask.CodTipo1 = Convert.ToInt32(cmbTipo.SelectedValue);
                objetask.CodPrio1 = Convert.ToInt32(cmbPrioridad.SelectedValue);
                objetask.CodEstad1 = Convert.ToInt32(cmbEstado.SelectedValue);
                objetask.CodResp1 = Convert.ToInt32(cmbResponsable.SelectedValue);
                objetask.FCreacion1 = Convert.ToDateTime(dateCreacion.Value);
                objetask.FInicio1 = Convert.ToDateTime(dateInicio.Value);
                objetask.FFin1 = Convert.ToDateTime(dateFin.Value);
                objetask.HInicio1 = Convert.ToDateTime(dateInicio.Value);
                objetask.HFin1 = Convert.ToDateTime(dateFin.Value);
                objetask.CodComplet1 = Convert.ToInt32(cmbCompletado.SelectedValue);
                objetask.Notas1 = txtNotas.Text;
                objetask.InsertarActividad();
                MessageBox.Show("Insertado correctamente");
                this.Close();
            }
            else if (operacion == "Editar")
            {
                objetask.CodActi1 = Convert.ToInt32(CodActi);
                objetask.DocRefeA1 = txtReferencia.Text;
                objetask.NomActivi1 = txtActividad.Text;
                objetask.CodTareas1 = Convert.ToInt32(cmbTarea.SelectedValue);
                objetask.CodTipo1 = Convert.ToInt32(cmbTipo.SelectedValue);
                objetask.CodPrio1 = Convert.ToInt32(cmbPrioridad.SelectedValue);
                objetask.CodEstad1 = Convert.ToInt32(cmbEstado.SelectedValue);
                objetask.CodResp1 = Convert.ToInt32(cmbResponsable.SelectedValue);
                objetask.FCreacion1 = Convert.ToDateTime(dateCreacion.Value);
                objetask.FInicio1 = Convert.ToDateTime(dateInicio.Value);
                objetask.FFin1 = Convert.ToDateTime(dateFin.Value);
                objetask.HInicio1 = Convert.ToDateTime(dateInicio.Value);
                objetask.HFin1 = Convert.ToDateTime(dateFin.Value);
                objetask.CodComplet1 = Convert.ToInt32(cmbCompletado.SelectedValue);
                objetask.Notas1 = txtNotas.Text;
                objetask.ActualizarActividad();
                MessageBox.Show("Se edito correctamente");
                this.Close();
            }
        }

Acá capturo el procedimiento almacenado los capos HInicio y HFin tienen definido un TimeOfDay

 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("@DocRefeA", DocRefeA);
                    command.Parameters.AddWithValue("@NomActivi", NomActivi);
                    command.Parameters.AddWithValue("@Codtareas", CodTareas);
                    command.Parameters.AddWithValue("@codtipo", CodTipo);
                    command.Parameters.AddWithValue("@codprio", CodPrio);
                    command.Parameters.AddWithValue("@codestad", CodEstad);
                    command.Parameters.AddWithValue("@codresp", CodResp);
                    command.Parameters.AddWithValue("@fcreacion", FCreacion);
                    command.Parameters.AddWithValue("@finicio", FInicio);
                    command.Parameters.AddWithValue("@ffin", FFin);
                    command.Parameters.AddWithValue("@HInicio", HInicio.TimeOfDay);
                    command.Parameters.AddWithValue("@HFin", HFin.TimeOfDay);
                    command.Parameters.AddWithValue("@CodComplet", CodComplet);
                    command.Parameters.AddWithValue("@Notas", Notas);
                    command.ExecuteNonQuery();
                    command.Parameters.Clear();
                }
            }
        }

Tabla de base de datos

CREATE TABLE [dbo].[tblactividad](
    [CodActi] [int] IDENTITY(1,1) NOT NULL,
    [DocRefeA] [varchar](8) NULL,
    [NomActivi] [nvarchar](100) NOT NULL,
    [CodTareas] [int] NULL,
    [CodTipo] [int] NULL,
    [CodPrio] [int] NULL,
    [CodEstad] [int] NULL,
    [CodResp] [int] NULL,
    [FCreacion] [datetime] NOT NULL,
    [FInicio] [datetime] NOT NULL,
    [FFin] [datetime] NOT NULL,
    [HInicio] [time](7) NULL,
    [HFin] [time](7) NULL,
    [Tiempo]  AS ((((right('0'+CONVERT([varchar](2),datediff(second,[HInicio],[HFin])/(3600)),(2))+':')+right('0'+CONVERT([varchar](2),(datediff(second,[HInicio],[HFin])%(3600))/(60)),(2)))+':')+right('0'+CONVERT([varchar](2),datediff(second,[HInicio],[HFin])%(60)),(2))) PERSISTED,
    [CodComplet] [int] NOT NULL,
    [Notas] [varchar](1000) NULL,)

¿Cómo ingresar la hora que yo elija mas no que ingrese la hora que tiene la app en el DateTimePiker?

1
  • Podrias agregar el Procedimiento Almacenado que tienes en SQL Server para esta operación? gracias.
    – arce.est
    el 24 jun. 2019 a las 18:02

0

Examina otras preguntas con la etiqueta o formula tu propia pregunta.