Results 1 to 4 of 4

Thread: [RESOLVED] Error Adding Record to Access 2000 using VB.NET 2005

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    90

    Resolved [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

  2. #2
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    90

    Re: Error Adding Record to Access 2000 using VB.NET 2005

    .....I'll get my coat

    Schoolboy error! Cheers for spotting it

    Andy

  4. #4
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Error Adding Record to Access 2000 using VB.NET 2005

    Quote 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
  •  



Click Here to Expand Forum to Full Width