Insert time and time into the database [closed]

1

I want to insert the time and date separately into the database, which has the timestamp and data fields, respectively.

I have the following code on the button that inserts:

SqlCommand sqlInsertCabecalho = 
new SqlCommand("Insert into cabecalho (nRequesicao,nomeEmpresa,colaborador,data,hora,nota) VALUES(@nRequesicao,@nomeEmpresa,@colaborador,@data,@hora,2nota)", sqlConn);

sqlInsertCabecalho.Parameters.AddWithValue("@nRequesicao", nRequesicao.ToString());
sqlInsertCabecalho.Parameters.AddWithValue("@nomeEmpresa", DropDownListEmpresa.Text);
sqlInsertCabecalho.Parameters.AddWithValue("@colaborador", Session["New"].ToString());
sqlInsertCabecalho.Parameters.AddWithValue("@data", DateTime.Now.ToString("yyyy-MM-dd"));
sqlInsertCabecalho.Parameters.AddWithValue("@hora", DateTime.Now.ToString("HH:mm:ss"));
sqlInsertCabecalho.Parameters.AddWithValue("@nota", TextBoxObservacoes.Text);

sqlConn.Open();
sqlTran = sqlConn.BeginTransaction();
sqlInsertCabecalho.Transaction = sqlTran;
sqlInsertCabecalho.ExecuteNonQuery();
sqlTran.Commit();
sqlConn.Close();

Response.Redirect("Consulta.aspx");

But I get an exception and do not insert. What am I doing wrong?

    
asked by anonymous 22.04.2016 / 15:48

2 answers

2

There is a typo, change to:

VALUES(@nRequesicao,@nomeEmpresa,@colaborador,@data,@hora,@nota)
    
22.04.2016 / 16:08
1

It's a typo, has a 2 instead of @ ( 2nota )

VALUES(@nRequesicao,@nomeEmpresa,@colaborador,@data,@hora,@nota)
    
22.04.2016 / 16:07