Kawaii, if Esat using MSSQL and wants 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
sqlInsertCabecalho.Parameters.Add("@data", SqlDbType.Date, 8).Value = DateTime.Today;
sqlInsertCabecalho.Parameters.Add("@hora", SqlDbType.Time, 5).Value = DateTime.Now.TimeOfDay;
if you cannot modify the database structure, you will need to adapt to this poorly done modeling, in its place I would do the date and time insert in the field data
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, including the same will be untracterized, but if you do otherwise, you will be misrepresenting the data type, and between keeping the semantics of the column name and the data type, 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 measure is to look for the administrator of the database and suggest modifying the types, thus following the recommendations of Microsoft itself.:
https://msdn.microsoft.com/en-us/library/ms187819.aspx
+1 in solidarity with -1 for no reason received.
– Tobias Mesquita
You’ll understand...
– Maniero