Kawaii, if esat using MSSQL and want to store a date and time in different fields, I advise you to change the field type to date
and time
respectively.
In any case, for new banks, it is advisable to avoid the use of types datetime
and timestamp
, use the not so new types date
, datetime2
, datetimeoffset
, time
p>
sqlInsertCabecalho.Parameters.Add("@data", SqlDbType.Date, 8).Value = DateTime.Today;
sqlInsertCabecalho.Parameters.Add("@hora", SqlDbType.Time, 5).Value = DateTime.Now.TimeOfDay;
If you can not modify the database structure, you will have to adapt to this poorly done model, in its place I would insert the date and time in the data
field and the timestamp/rowversion
provided by the system in the field hora
.
In this case the name of the field will not be self explanatory, even the same will be deprecated, but if you do otherwise, you will be typing the type of the data, and between maintaining the semantics of the column name and type of data, I prefer the type.
SqlCommand sqlInsertCabecalho =
new SqlCommand("Insert into cabecalho (nRequesicao,nomeEmpresa,colaborador,data,nota) VALUES(@nRequesicao,@nomeEmpresa,@colaborador,@data,2nota)", sqlConn);
sqlInsertCabecalho.Parameters.Add("@nRequesicao", SqlDbType.Int, 4).Value = nRequesicao; // estou assumindo que está utilizando um campo int
sqlInsertCabecalho.Parameters.Add("@nomeEmpresa", SqlDbType.VarChar, 50).Value = DropDownListEmpresa.Text; // estou assumindo que está utilizando um campo varchar(50)
sqlInsertCabecalho.Parameters.Add("@colaborador", SqlDbType.VarChar, 50).Value = Session["New"].ToString(); // estou assumindo que está utilizando um campo varchar(50)
sqlInsertCabecalho.Parameters.Add("@data", SqlDbType.DateTime, 8).Value = DateTime.Now; // estou assumindo que está utilizando um campo datetime
sqlInsertCabecalho.Parameters.Add("@nota", SqlDbType.VarChar, 10).Value = Session["New"].ToString()); // estou assumindo que está utilizando um campo varchar(10)
But the best thing is to look for the database administrator and suggest modifying the types, so follow the recommendations of Microsoft itself:
link