Home All Groups Group Topic Archive Search About

How to set the SmallDateTime field

Author
7 Jul 2006 7:26 PM
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?

Author
8 Jul 2006 3:34 PM
Cowboy (Gregory A. Beamer)
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!
*************************************************
Show quote
"ad" <fly***@wfes.tcc.edu.tw> wrote in message
news:%23Q27%23sfoGHA.4776@TK2MSFTNGP03.phx.gbl...
>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?
>
>

AddThis Social Bookmark Button