Link to home
Start Free TrialLog in
Avatar of salman_sulaiman_2008
salman_sulaiman_2008

asked on

How Can I Store "Date" values from my web application to a table in MS.SQL SERVER with field datatype "DateTime"??

Greetings Experts!
I can't figure out what the problem is, It is when I try to store "dates" into slq server 2005 table which has a field of datatype "datetime", I have written a query which inserts the date values as a string from withing my web application, I have attached the code in the code snippet.

but when debugging, I get an error message saying conversion is not possible to datetime from char string.

Hope someone could help me with it.
thanks in advance
~salman~

myInsertSQLStatement = myInsertSQLStatement + "insert into trans_acc (record_no, outer_no, inner_no, id_main, id_sub, transaction_type, transaction_amount, tkn_no, trans_date) values (" & starting_record_no & ", " & starting_outer_no & ", " & starting_inner_no & ", " & ID_Main & ", " & ID_SUB & ", N'" & trans_type & "', " & trans_amount & ", " & CInt(Request.Cookies("TKN_NO").Value) & ",'" & Today.Date.ToString & "') ;"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
can you paste here value of  myInsertSQLStatement ?

Where you are getting error ? while inserting to databse?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of salman_sulaiman_2008
salman_sulaiman_2008

ASKER

greetings everyone!
thanks for the reply guys!

the truth is, I need to insert into the sql server table a date value which was selected  by the user, I am using "calendarpopup" control which I downloaded it from a web site but can't remember what it was.

but here what I did and it sorted out my problem, I created a stored procedure called "Insert_trans_acc" in sql server, and I passed to it all  the required fields, and when it came to the field "trans_date", which is of type "datetime", i passed to it the following:

DateTime.ParseExact(CalendarPopup1.SelectedDate.ToString, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture)

and It works like magic..!

Best Wishes & blessings,
~salman~
greetings everyone!
thanks for the reply guys!

the truth is, I need to insert into the sql server table a date value which was selected  by the user, I am using "calendarpopup" control which I downloaded it from a web site but can't remember what it was.

but here what I did and it sorted out my problem, I created a stored procedure called "Insert_trans_acc" in sql server, and I passed to it all  the required fields, and when it came to the field "trans_date", which is of type "datetime", i passed to it the following:

DateTime.ParseExact(CalendarPopup1.SelectedDate.ToString, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture)

and It works like magic..!

Best Wishes & blessings,
~salman~