I am trying the following code and getting the sql date time overflow exception…..The problem lies in the Gold part…rest to i.e. Silver and Premium work fine….When in Gold part I try to add certain number of months to a date time field I don’t know what action is performed as when i check it through Message box the ren_date has value “12:00:00 AM” rather than the new date value after adding 6 months in mem_date value….
Dim ren_date, mem_date As Date
Dim renmon As String
mem_date = TxtMemDate.Text
' checks the type of membership and adds corresponding number of years to the membership date and stores in renewal date
If ComboBox1.SelectedItem = "Silver" Then
ren_date = mem_date.AddMonths(3)
renmon = ren_date.ToString("MMMM")
ElseIf ComboBox1.SelectedItem = "Premium" Then
ren_date = mem_date.AddYears(1)
renmon = ren_date.ToString("MMMM")
ElseIf ComboBox1.SelectedItem = "Gold" Then
ren_date = mem_date.AddMonths(6)
renmon = ren_date.ToString("MMMM")
End If
MsgBox(mem_date)
MsgBox(ren_date)
I suspect your issue is actually here:
It may be that the
Stringyou’re trying to coerce to aDatehere isn’t in the right format. Try putting a breakpoint after this line and go through with a debugger to experiment.Here’s another thing to try: maybe your
ComboBox1.SelectedItemdoes not exactly match the string “Gold.” Add anElseblock to yourIfand put in there something likeThis should reveal if there are, for example, leading or trailing spaces around the item’s text.