[RESOLVED] Error Adding Record to Access 2000 using VB.NET 2005
Hi All
I'm trying to add a record to an MS Access table. The following code gives me the error "Object reference not set to an instance of an object." :-
Code:
Dim con As New OleDb.OleDbConnection
strConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & strDBPath
con.ConnectionString = strConnectionString
con.Open()
Dim runDS As New DataSet
Dim runDA As OleDb.OleDbDataAdapter
strSQL = "SELECT * FROM tblRuns"
runDA = New OleDb.OleDbDataAdapter(strSQL, con)
runDA.Fill(runDS, "Runs")
Dim runCB As New OleDb.OleDbCommandBuilder(runDA)
Dim dsNewRow As DataRow
'ERROR OCCURS HERE
dsNewRow = runDS.Tables("Run").NewRow
dsNewRow.Item("fldEventTitle") = strCurrentEventTitle
runDS.Tables("Run").Rows.Add(dsNewRow)
runDA.Update(runDS, "Run")
runDS.Clear()
runDS.Dispose()
runCB.Dispose()
runDA.Dispose()
con.Close()
con.Dispose()
What's confusing me is that this same code works elsewhere in my app!
Anyone any idea?
You're confusedly
Andy
Re: Error Adding Record to Access 2000 using VB.NET 2005
change
Code:
dsNewRow = runDS.Tables("Run").NewRow
to
Code:
dsNewRow = runDS.Tables("Runs").NewRow
or simply
runDA.Fill(runDS, "Runs") to runDA.Fill(runDS, "Run") :D
Re: Error Adding Record to Access 2000 using VB.NET 2005
.....I'll get my coat :blush:
Schoolboy error! Cheers for spotting it :thumb:
Andy
Re: Error Adding Record to Access 2000 using VB.NET 2005
Quote:
Originally Posted by Duckfather
.....I'll get my coat :blush:
Schoolboy error! Cheers for spotting it :thumb:
Andy
Is it ! :D