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?