Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-07-10 : 09:11:56
|
| Garceson writes "Dear friends,I am struggling to insert a date value in "dd-mm-yyyy" format to SQL server table having datatype as Date/Time. Regional date setting for Server and Local systems are in dd-mm-yyyy format.I am using following codeDim DT As StringDT = Now()DT = Format(DT, "MM/DD/YYYY")for the inserting into table using commandins_comm.CommandText = " INSERT INTO CARD (doe) values("& DT &")"Procedure will end without any error ,but stored value for the date feild will be garbage value like 1900-01-01.But if i used mm-dd-yyyy format ,it will get inserted.What could be the reason,How I can save value in dd-mm-yyyy or dd-mm-yy formatPlease help!!!Graceson Mathew" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-10 : 09:20:46
|
| Always format the date with YYYYMMDD format which is universal and will work regardless of any date settingsTry Dim DT As StringDT = Now()DT = Format(DT, "YYYYMMDD")ins_comm.CommandText = " INSERT INTO CARD (doe) values('"& DT &"')"Also, use stored procedures with parameters and avoid using Concatenated SQL statementsMadhivananFailing to plan is Planning to fail |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-07-10 : 09:32:44
|
Use parameters, even if you don't want to use stored procs. And always use proper datatypes, both for your client code and when using SQL Server. If you are using .Net, then use Date property of a DateTime to return the date part only. And then set a parameter to that value.Dim DT As StringDateTimeDT = Now().DateDT = Format(DT, "MM/DD/YYYY")ins_comm.CommandText = " INSERT INTO CARD (doe) values(@DT)"ins_comm.parameters.add("@DT",sqlDBType.DateTime).value = DTins_comm.executeNonQuery()- Jeff |
 |
|
|
|
|
|
|
|