You should have to include "Error/Exception" trace to your post. The error says that you've some reference variables that contains null. Please verify ds and da variables.
Use Using to ensure the ADO resources are disposed properly:
Using Cn As New OleDb.OleDbConnection
Using Cmd As New OleDb.OleDbCommand
Cn.ConnectionString = "your_connection_string"
Cmd.CommandText = "INSERT INTO SAMPLE (NO,NAME) VALUES (@no,@name)"
Cmd.Parameters.AddWithValue("@no",10)
Cmd.Parameters.AddWithValue("@name","foo")
Cn.Open()
Cmd.ExecuteNonQuery()
Cn.Close()
End Using
End Using
__avd
Posting Genius (adatapost)
8,736 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 50
You are trying to add a row to a datatable called "Sample". This datatable doesn't exist -yet.
First fill your datatable - which will create it- and then try to add a new row to it.
Alternatively you might want to think inserting the record to your db without the dataset/datatable & dataadapter.
By the way, since you didn't assign a value to inc, the If inc <> -1 will always return true.
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11