0
I want to enter the time and date separately in the database, which have the fields timestamp
and data
, respectively.
I have the following code on the insert button:
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 however I get an exception and does not insert. What I am doing wrong?
Tell me the exception. What is the value you’re trying to use? I have an idea, but I don’t want to guess.
– Maniero
@bigown I am trying to use the automatic date/time value, the exection says that there is an incorrect syntax.
– Kawaii
@I don’t know if I don’t understand the question or explained it wrong, but I want to enter the current time and date value of when the insertion is made. Hence the 'Datetime.Now'
– Kawaii
Yeah, okay, so that’s not the problem. I need more detail, the line where the error occurs, the exact exception. I think the mistake isn’t even in those lines, they’re correct. Unless you don’t have the
@data
or@hora
inside the command you’re mounting.– Maniero
Can you [Edit] your question and add the exact exception? And also the content of
sqlInsertCabecalho
.– Jéf Bueno
@jbueno made the changes
– Kawaii
@moustache I edited and added the detail
– Kawaii