Reputation: 1
I'm currently making an event program in VB.NET where the user can add daily/weekly/monthly/yearly events to a database. Their are two options : -Adding the occurrence x times to a StartDate. (https://i.sstatic.net/5ZmuI.png^]) -Adding the occurrence between a StartDate and an EndDate. (https://i.sstatic.net/FUko3.png^]) When i'm adding the weeks from 2 april until 29 of may / 2 april x times it generates some random values in it. Is there any way of fixing this ? This is my code :
Case rbnWeekly.Checked 'Weekly mode with Enddate and StartDate
If rbnStartEnd.Checked = True Then
Dim startDate As Date = dtpStartDate.Text
Dim endDate As Date = dtpEndDate.Text
Dim currDate As Date = startDate
Do While (currDate < endDate)
SQL = String.Format("INSERT INTO tblManual (StartDate, EndDate, UniqueID) VALUES (#{0}#, #{1}#, '{2}')", currDate, endDate, id)
scmdRecurrence.CommandText = SQL
Valueee += 1
scmdRecurrence.ExecuteNonQuery()
currDate = currDate.AddDays(7)
Loop
MsgBox(Valueee.ToString & " records toegevoegd")
Else 'Weekly mode with x times
Dim aantal As Integer = txtHerhaling.Text
Dim startDate As Date = Date.Today
Dim endDate As Date = startDate.AddDays(aantal * 7)
Dim currDate As Date = startDate
Do While (currDate < endDate)
SQL = String.Format("INSERT INTO tblManual (StartDate, EndDate, UniqueID) VALUES (#{0}#, #{1}#, '{2}')", currDate, endDate, id)
scmdRecurrence.CommandText = SQL
Valueee += 1
scmdRecurrence.ExecuteNonQuery()
currDate = currDate.AddDays(7)
Loop
MsgBox(Valueee.ToString & " records toegevoegd")
End If
Upvotes: 0
Views: 816
Reputation: 56016
In the SQL, you need properly formatted string expressions for the date values to be inserted:
.. , currDate.ToString("yyyy'/'MM'/'dd"), endDate.ToString("yyyy'/'MM'/'dd"), id)
Upvotes: 1