|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to set the SmallDateTime fieldI 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. -- Show quoteGregory A. Beamer ************************************************* Think Outside the Box! ************************************************* "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? > > |
|||||||||||||||||||||||