I am trying to seed a table with dates in between two dates. I did this in Access and I'm trying to figure out how to do it in Visual Studio 2008. Here is the Access code:
'variables
Dim sql1, sql2, sql3 As String, s1, s2 As Recordset
Dim tag1, msg As String, i As Long
Dim d1, d2, d3 As Variant, title As String
Dim mydb As Database
Set mydb = Currentdb()
' prompt the user for dates
'startDate
d1 = DateAdd("d", -30, Now())
d1 = Format(d1, "mm/dd/yyyy")
msg = "Enter the beginning date ->"
title = "Get Bldg Dates"
d1 = CDate(InputBox(msg, title, d1))
'endDate
d2 = Format(Now(), "mm/dd/yyyy")
msg = "Enter the " & vbCrLf & "ending date ->"
title = "Get Bldg Dates"
d2 = CDate(InputBox(msg, title, d2))
' seed the table with days
sql1 = " SELECT * FROM [Table - Bldg 650];"
Set s1 = mydb.OpenRecordset(sql1, DB_OPEN_DYNASET, dbSeeChanges)
d3 = d1
Do While d3 <= d2
s1.AddNew
s1!Date = d3
s1.Update
d3 = DateAdd("d", 1, d3)
Loop
In VS2008, I am trying to eliminate the need for inputing a start and end date. The code below reflects that change:
Imports System.Data.Linq
Public Class frmTransferData
Dim systemData As New PFSystemDataContext
Public dateNow As Date = Now().Date
Public dateYesterday As Date
Private Sub frmTransferData_Load(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim startDate = pckrStartDate.Value.ToStri
ng("yyyy-M
M-dd 00:00:01")
Dim endDate = pckrEndDate.Value.ToString
("yyyy-MM-
dd 11:59:59")
Dim dateYesterday = dateNow.AddDays(-1).Date
'open tbleBldg650 and get the last date
Dim lastDate = From id In systemData.tblBldg650s _
Let selectDate = id.Date _
Order By selectDate Descending _
Select id.Date _
Take 1
'add the date for each day in between the last date and dateYesterday
Do While dateYesterday.ToString <= lastDate.ToString
'add a new row to tblBldg650
'the date column = lastdate +1
'update
'then add conseq dates until dateYesterday is reached
Loop
End Sub
I have tried several different ways with no success to include collecting the dates in between the two dates, putting them in a table and trying to force them into table by row.add etc.
FYI - I "seed" this table with the dates, then I go back to the original table and take that date's data (240 records) and average it, sticking that average in this "seeded" table for charting purposes.
Any help would be GREATLY appreciated.