Updating datasource reports an error

G

Georges

Hi!

Could someone help?

I'm having trouble with the following code. Everythig goes fine till the
last line where I'm trying to update the datasource. The program stops
executing and displays the message "No value given for one or more required
parameters." I tried many ways of doing the same, nothing works.

Public Class FormX
Private Sub FormX_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim MyCNN As New Data.OleDb.OleDbConnection
MyCNN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\MyDB.mdb"

Dim SelectStatement As String = "SELECT Field1, Field2, Field3 FROM
MyTable"
Dim MyDA As New Data.OleDb.OleDbDataAdapter(SelectStatement, MyCNN)

Dim strInsertCmd As String = "INSERT INTO MyTable (Field1, Field2,
Field3) VALUES (?, ?, ?)"
Dim InsertCmd As New Data.OleDb.OleDbCommand(strInsertCmd, MyCNN)
MyDA.InsertCommand = InsertCmd

Dim MyDS As New DataSet
MyDA.Fill(MyDS, "TableName")

Dim drNew As DataRow
drNew = MyDS.Tables("TableName").NewRow
drNew.Item("Field1") = "New value" 'string field
drNew.Item("Field2") = 12 'integer
drNew.Item("Field3") = 123 'integer
MyDS.Tables("TableName").Rows.Add(drNew)

MyDA.Update(MyDS, "TableName") <------------ the offending code
End Sub
End Class

I'd really like to understand what's going on.

Thanks,

Georges
 
R

Radenko Zec

Where is your Update Command like this insert command?
Dim strInsertCmd As String = "INSERT INTO MyTable (Field1, Field2,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top