|
-
Jul 23rd, 2008, 04:26 PM
#1
Thread Starter
Lively Member
[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
-
Jul 23rd, 2008, 04:31 PM
#2
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")
__________________
Rate the posts that helped you 
-
Jul 23rd, 2008, 04:35 PM
#3
Thread Starter
Lively Member
Re: Error Adding Record to Access 2000 using VB.NET 2005
.....I'll get my coat
Schoolboy error! Cheers for spotting it
Andy
-
Jul 23rd, 2008, 04:38 PM
#4
Re: Error Adding Record to Access 2000 using VB.NET 2005
 Originally Posted by Duckfather
.....I'll get my coat
Schoolboy error! Cheers for spotting it
Andy
Is it !
__________________
Rate the posts that helped you 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|