How to set the SmallDateTime field

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I have a Table with a SmallDateTime field name OrderDate.
I want to insert a record into this table, I use the SQL below:

sSqlLogIns = "Insert Into hInfLog (OrderID, OrderDate) values ('{0}',{1})
";
sSqlLogIns = string.Format(sOrderID, DateTime.Now.ToString());


Was I use DateTime.Now.ToString() OK?

or I must I use ToShortDateString() or others?
 
Use parameters instead. If OleDb, use ? as placeholders for the parameters
(the params have to be attached in order). If SqlClient, name the parameters
in the string.

If you do this, you do not have to worry about the format string.

NOTE: SmallDateTime can take long values. If you are having problem it is a
wrong string format. ToShortDateString() will work, as long as you do not
require time in the value (a short date string will always be midnight).
Parameters are STILL a better option.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
Back
Top