Hi. I am new to this forum, but i have been playing with Visual Basic since 4.0.

Anyway here is my problem. I am getting error and can't figure out why.

Dim connectionString As String
        Dim cnn As OleDbConnection
        connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Database\tmprcStavka.mdb;"
        cnn = New OleDbConnection(connectionString)
            MsgBox("Connection Open ! ")
            Dim ds As New DataSet
            Dim da As OleDb.OleDbDataAdapter
            Dim Sql As String = "INSERT INTO RacuniStavke"

            da = New OleDb.OleDbDataAdapter(Sql, cnn)
            Dim cb As New OleDb.OleDbCommandBuilder(da)
            cntx = 0
            Do Until cntx = dbtStavke.RowCount - 1

                ArtikalIznos = dbtStavke.Rows(cntx).Cells("IznosDataGridViewTextBoxColumn").Value()
                ArtikalNaziv = dbtStavke.Rows(cntx).Cells("ArtikalDataGridViewTextBoxColumn").Value()
                ArtikalJMJ = dbtStavke.Rows(cntx).Cells("JMJDataGridViewTextBoxColumn").Value()
                ArtikalKolicina = dbtStavke.Rows(cntx).Cells("KolicinaDataGridViewTextBoxColumn").Value()
                ArtikalCijena = dbtStavke.Rows(cntx).Cells("IznosDataGridViewTextBoxColumn").Value()

                Dim dsNewRow As DataRow = ds.Tables("RacunStavka").NewRow()
                dsNewRow.Item("BrRacun") = brojrc
                dsNewRow.Item("ArtikalNaziv") = ArtikalNaziv
                dsNewRow.Item("ArtikalJMJ") = ArtikalJMJ
                dsNewRow.Item("ArtikalKolicina") = ArtikalKolicina
                dsNewRow.Item("ArtikalCijena") = ArtikalCijena
                dsNewRow.Item("ArtikalIznos") = ArtikalIznos


                da.Update(ds, "RacunStavka")

                cntx = cntx + 1

            CTX = 1
        Catch ex As Exception
            MsgBox("Can not open connection ! " & ex.Message & vbCrLf & ex.StackTrace)
        End Try

I am quite sure that it's some silly error but can't quite figure out what. I am using mdb only in this case and it's used only to export some data from MDF database.

Error is:

"Object reference not set to an instance of an object"

It's breaking right here:

Dim dsNewRow As DataRow = ds.Tables("RacunStavka").NewRow()
dsNewRow.Item("BrRacun") = brojrc

Table and field exist and there is no typo. Checked at least five times ;)

I hope this is enough information. Thank you in advance.

Edited by Bodul: n/a

7 Years
Discussion Span
Last Post by Bodul

I figured a better way (better for me at least).
So this is solved.

Thanks !

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.