tia_kamakshi
asked on
Insert query with datetime
Hi, I am working on MSSQL, C#, ASP.Net 1.1
I have DataTime in variable
DateTime dtContactDate = txtContactDate.SelectedDat e;
having the value = 7/25/2007
I create a insert query string at runtime so I get the insert query in the form
INSERT INTO SleepingCustomerContactDat es([Custom erId],[Con tactedDate ],[Remarks ])Values (430,'25/07/2007 10:33:18','Test');
Now, I changed above DateTime to string as below
string strContactDate = dtContactDate.ToShortDateS tring();
I get the value "25/07/2007"
and then I get my inserts statement generated as below
INSERT INTO SleepingCustomerContactDat es([Custom erId],[Con tactedDate ],[Remarks ])Values (430,'25/07/2007','Test');
In both the cases when I execute the insert query, I get the error below:
Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.
In C#, I create the query as below
strQuery = strQuery+"INSERT INTO SleepingCustomerContactDat es([Custom erId],[Con tactedDate ],[Remarks ])"+
"Values ("+strCustomerId+",'"+strC ontactDate +"','"+str Remarks+"' );";
How to solve the problem
Please help
I have DataTime in variable
DateTime dtContactDate = txtContactDate.SelectedDat
having the value = 7/25/2007
I create a insert query string at runtime so I get the insert query in the form
INSERT INTO SleepingCustomerContactDat
Now, I changed above DateTime to string as below
string strContactDate = dtContactDate.ToShortDateS
I get the value "25/07/2007"
and then I get my inserts statement generated as below
INSERT INTO SleepingCustomerContactDat
In both the cases when I execute the insert query, I get the error below:
Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.
In C#, I create the query as below
strQuery = strQuery+"INSERT INTO SleepingCustomerContactDat
"Values ("+strCustomerId+",'"+strC
How to solve the problem
Please help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.