Answered by:
SQL Date problem.. inserting wrong date.

Question
-
User-20868959 posted
Hi i am working in the vb.net and inserting the date into DATETIME field sql db. During duging am checking it shows correct date but when insert into db it show "1/1/1900 00:00:00" . I dont know whats the problem.
Code:
Dim ObjDob As DateTime = CDate(Me.ddlDates.SelectedValue & "/" & Me.ddlMonths.SelectedValue & "/" & Me.ddlYears.SelectedValue).ToString("dd/MM/yyyy")
your comments will be appriciated.
Thanks
GM.
Wednesday, December 15, 2010 12:54 PM
Answers
-
User-2115483147 posted
Please try two ways below to check your code first,
1. Please set a check point in the IDE of the "Microsoft Visual Studio" to check the variable of "ObjDob", is that correct?
2. Use SQL Server Profiler to monitor the executed SQL Query, make sure the SQL Query is correct.
Now, I think you can use above ways find out the the issue, then I think you can easy to fix this issue via an other way. Or please refer 1 & 2 to check it again.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 21, 2010 9:00 PM
All replies
-
User-821857111 posted
Change the order of the dropdowns when you construct the date from them so that it's yyyy-mm-dd. Then it won't be culture-specific.
Wednesday, December 15, 2010 2:13 PM -
User-1590642642 posted
You might try DIM-ing ObjDob as SqlDateTime instead of DateTime. If that doesn't do it, please post the part of your code where you plug ObjDob into your INSERT statement.
Wednesday, December 15, 2010 2:30 PM -
User154448021 posted
this is the correction for my previous post. it seems to be that the date you entered was lost before it was inserted. please check if there is any postback in pageload that may reset the value.
Wednesday, December 15, 2010 2:40 PM -
User-20868959 posted
Change the order of the dropdowns when you construct the date from them so that it's yyyy-mm-dd. Then it won't be culture-specific.
Hi,
I have changed the sequence as mentioned but still the same situation, Any one can tell me how to store the selected date. There is not refresh page, i am getting the exact value in the objDob datetime type variable and at the end means before excuting the query have the selected value but when inserting into db then it shows wrong date " 1 / 1/1900 00:00:00".
Dim ObjDob As DateTime = CDate(Me.ddlYears.SelectedValue & "/" & Me.ddlMonths.SelectedValue & "/" & Me.ddlDates.SelectedValue).ToString("yyy/mm/dd")
Dont know how to fix it.
Any comments will be appriciated.
GM
Thursday, December 16, 2010 4:38 AM -
User1867929564 posted
If u r using sp then it is neccessary to see it.may be some bad code written there.
also you need to show other part of code which insert.
what exact value you getting in ObjDob ?Thursday, December 16, 2010 5:36 AM -
User-2115483147 posted
Please try two ways below to check your code first,
1. Please set a check point in the IDE of the "Microsoft Visual Studio" to check the variable of "ObjDob", is that correct?
2. Use SQL Server Profiler to monitor the executed SQL Query, make sure the SQL Query is correct.
Now, I think you can use above ways find out the the issue, then I think you can easy to fix this issue via an other way. Or please refer 1 & 2 to check it again.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 21, 2010 9:00 PM