|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Updating datasource reports an errorCould 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 Where is your Update Command like this insert command?
Dim strInsertCmd As String = "INSERT INTO MyTable (Field1, Field2, Show quote > Field3) VALUES (?, ?, ?)" > Dim InsertCmd As New Data.OleDb.OleDbCommand(strInsertCmd, MyCNN) > MyDA.InsertCommand = InsertCmd "Georges" <gdufr***@videotron.ca> wrote in message news:JDf6g.66758$hR6.601651@weber.videotron.net... > 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 > > > |
|||||||||||||||||||||||