Hi,

What's the problem in the below code...

Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("mr_head").NewRow()

I am getting the below error :
Object reference not set to an instance of an object.

Do you actually have a table called "mr_head"?

You've just declared the dataset and you are trying to insert a row to a non-existing table.

You've just declared the dataset and you are trying to insert a row to a non-existing table.

Could you please correct the code for me ...

Hello !
i think adam_k is right , u have to use datatable for it or give table name to the dataset ,

dim dt as new datatable
'OR
dim ds as new dataset
ds.table("Table1").clear ' now you have a table name table1 in your dataset

Hello !
i think adam_k is right , u have to use datatable for it or give table name to the dataset ,

dim dt as new datatable
'OR
dim ds as new dataset
ds.table("Table1").clear ' now you have a table name table1 in your dataset

con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = d:/sprrg/sprrg.mdb"
con.Open()

Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsnewrow As DataRow

dsnewrow = ds.Tables("mr_head").NewRow()

ds.Tables("mr_head").Rows.Add(dsnewrow)

dsnewrow.Item("job_code") = TextBox1.Text
dsnewrow.Item("mr_no") = TextBox2.Text
dsnewrow.Item("mr_date") = TextBox3.Text

da.Update(ds, "mr_head")

MsgBox("Updated")

Could you please check whether this is correct

Did you make a change?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.