Hello all,
I am creating a project for myself to practice Database connectivity, updating, deleting and adding items.
I am having an issue updating one of the tables i have added, within a table there is a column called Today's Date which will contain the date the last time the program ran, when i run the program i want it to update that column with the new date.
Imports FinancialBalanceSheet.AllAccessDBConnections
'Form 1 Data
Public Class StarterPage
Private Sub StarterPage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objDBItems As AllDBUses
objDBItems = New AllDBUses
objDBItems.OpenAllTables()
objDBItems.UpdateTodaysDateOnTables()
End Sub
End Class
Imports System.Data
Namespace AllAccessDBConnections
Class AllDBUses
Private con As New OleDb.OleDbConnection
Private ds As New DataSet
Private da As OleDb.OleDbDataAdapter
Private sql As String
Public Sub OpenAllTables()
'CONNECTIONSTRING - THIS IS WHERE THE CONNECTION TAKES PLACE
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\Danny\Desktop\Financial Data\FinancialBalanceSheetDB.mdb"
con.Open() 'OPEN CONNECTION
sql = "SELECT * FROM Income" 'OPEN ALL DATA IN INCOME TABLE
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Income")
Sql = "SELECT * FROM Expenditure" 'OPEN ALL DATA IN EXPENDITURE TABLE
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "Expenditure")
sql = "SELECT * FROM Savings" 'OPEN ALL DATA IN SAVINGS TABLE
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Savings")
con.Close() 'CLOSE CONNECTION
End Sub
Public Sub UpdateTodaysDateOnTables()
Dim rowNumber As Integer = 0
Dim maxRowsExpenditure As Integer
Dim maxRowsSavings As Integer
Dim currentDate As String
Dim todaysDate As Date = DateTime.Now
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim updateExpenditureDate As Boolean = False
todaysDate = todaysDate.ToString("dd/MM/yyyy")
maxRowsExpenditure = ds.Tables("Expenditure").Rows.Count
maxRowsSavings = ds.Tables("Savings").Rows.Count
Do Until rowNumber = maxRowsExpenditure
currentDate = ds.Tables("Expenditure").Rows(rowNumber).Item("Todays Date")
If currentDate <> todaysDate Then
currentDate = todaysDate
ds.Tables("Expenditure").Rows(rowNumber).Item("Todays Date") = currentDate
updateExpenditureDate = True
End If
rowNumber = rowNumber + 1
Loop
If updateExpenditureDate = True Then
da.Update(ds, "Expenditure")
End If
rowNumber = 0
End Sub
End Class
End Namespace
When the code runs to 'da.Udate(ds, "Expenditure") I get the following error:
Missing the DataColumn 'Asset Name' in the DataTable 'Expenditure' for the SourceColumn 'Asset Name'.
The 'Asset Name' mentioned in the error is a column name but it is in my two other tables, why would it be reading them when I specify the table.
Any help will be much appreciated.
Thanks