Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've been struggling with a recurrence mode for inserting my dates into a database.
I'm capable of adding StartDays and EndDates, I didn't find a good way of recurring my days over a period of time.
The user must be capable of repeating the event daily, weekly, monthly and yearly.
All the tutorials on the internet are either for ASP.NET/C#. I'm using VB.NET and an Access database.
Thanks in advance.
Posted
Updated 25-Jul-19 10:23am
v3
Comments
PIEBALDconsult 18-Apr-15 19:32pm    
You won't like it, but : http://en.wikipedia.org/wiki/ISO_8601#Repeating_intervals
Member 11385046 18-Apr-15 19:38pm    
So is there some way of implementing this into VB code ?
Sergey Alexandrovich Kryukov 18-Apr-15 19:36pm    
What do you mean by "VB". What does it mean, ASP/C#? I never heard about C# used with ASP. If you mean "APS.NET", this is not ASP.
—SA
Member 11385046 18-Apr-15 19:44pm    
I'm currently writing the local program in VB.NET. All the tutorials for recurring dates are either written in C# or ASP.NET.
Sergey Alexandrovich Kryukov 18-Apr-15 19:48pm    
Good, thank your for the clarification. Then better click "Improve question" and add this ".NET" to "VB", and "ASP", to make your post not so confusing. You are the one who is interested in that the most.
Also, it will be useful to define exactly how "recurring" should work. I don't think it's clear.
—SA

1 solution

If i understand you well...

MS Access database does not supports recurrence in queries. You have to write method as below:
VB
Dim startDate As Date = Date.Today()
Dim endDate As Date = startDate.AddDays(15)
Dim currDate As Date = startDate

Do While (currDate < endDate)
    Console.WriteLine("INSERT INTO TableName (StartDate, EndDate) VALUES ({0}, {1})", currDate, endDate)
    currDate = currDate.AddDays(1)
Loop


As you can see, i'm using Do... Loop[^] statement to loop through the dates.
 
Share this answer
 
Comments
Member 11385046 19-Apr-15 9:19am    
Thank you,
I have been trying to replace the Console.Writeline command with Oledb commands.
It's not working and giving an error : http://i.imgur.com/WqB1k3v.png
Is there any way of solving this ?
Public Class Manual

Private Sub Manual_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Commands & connections
Dim con As New OleDb.OleDbConnection
Dim cmd As New OleDb.OleDbCommand
Dim Sql As String
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\TonesToDoList\1tabel1.accdb"
con.Open()
'Recurrence
Dim startDate As Date = Date.Today()
Dim endDate As Date = startDate.AddDays(15)
Dim currDate As Date = startDate

Do While (currDate < endDate)
Sql = ("INSERT INTO tblManual (StartDate, EndDate)" & "VALUES ({0}, {1})", currDate, endDate)
cmd.ExecuteNonQuery()
currDate = currDate.AddDays(1)
Loop
con.Close()
End Sub

End Class
Maciej Los 19-Apr-15 12:30pm    
Replace this: Sql = ("INSERT INTO tblManual (StartDate, EndDate)" & "VALUES ({0}, {1})", currDate, endDate) with: Sql = String.Format("INSERT INTO tblManual (StartDate, EndDate) VALUES (#{0}#, #{1}#)", currDate, endDate)
Member 11385046 19-Apr-15 13:25pm    
The current code does not add anything into the database. Code runs without errors though.

Public Class Form1

Private Sub Recurrence_Click(sender As System.Object, e As System.EventArgs) Handles Recurrence.Click
'Delcareren
Dim cnnRecurrence As New OleDb.OleDbConnection
Dim scmdRecurrence As New OleDb.OleDbCommand
Dim SQL As String
'Connectionstring
cnnRecurrence.ConnectionString = My.Settings._1tabel1ConnectionString
scmdRecurrence.Connection = cnnRecurrence
cnnRecurrence.Open()
'Recurrence
Dim startDate As Date = Date.Today()
Dim endDate As Date = startDate.AddDays(15)
Dim currDate As Date = startDate
Do While (currDate < endDate)
SQL = String.Format("INSERT INTO tblManual (StartDate, EndDate) VALUES (#{0}#, #{1}#)", currDate, endDate)
currDate = currDate.AddDays(1)
Loop
cnnRecurrence.Close()
End Sub
End Class
Maciej Los 19-Apr-15 13:29pm    
Because you never call: 'REM: after SQL = String.Format("...")
scmdRecurrence.CommandText = SQL
scmdRecurrence.ExecuteNonQuery()
'REM: before currDate = ....
:)
Member 11385046 19-Apr-15 13:55pm    
Thank you ,that's successful ! So this is for daily occasions so how do I add monthly/weekly/yearly events?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900