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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyCNN As New Data.OleDb.OleD bConnection
MyCNN.Connectio nString = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=|DataDir ectory|\MyDB.md b"
Dim SelectStatement As String = "SELECT Field1, Field2, Field3 FROM
MyTable"
Dim MyDA As New Data.OleDb.OleD bDataAdapter(Se lectStatement, MyCNN)
Dim strInsertCmd As String = "INSERT INTO MyTable (Field1, Field2,
Field3) VALUES (?, ?, ?)"
Dim InsertCmd As New Data.OleDb.OleD bCommand(strIns ertCmd, MyCNN)
MyDA.InsertComm and = InsertCmd
Dim MyDS As New DataSet
MyDA.Fill(MyDS, "TableName" )
Dim drNew As DataRow
drNew = MyDS.Tables("Ta bleName").NewRo w
drNew.Item("Fie ld1") = "New value" 'string field
drNew.Item("Fie ld2") = 12 'integer
drNew.Item("Fie ld3") = 123 'integer
MyDS.Tables("Ta bleName").Rows. Add(drNew)
MyDA.Update(MyD S, "TableName" ) <------------ the offending code
End Sub
End Class
I'd really like to understand what's going on.
Thanks,
Georges
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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim MyCNN As New Data.OleDb.OleD bConnection
MyCNN.Connectio nString = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=|DataDir ectory|\MyDB.md b"
Dim SelectStatement As String = "SELECT Field1, Field2, Field3 FROM
MyTable"
Dim MyDA As New Data.OleDb.OleD bDataAdapter(Se lectStatement, MyCNN)
Dim strInsertCmd As String = "INSERT INTO MyTable (Field1, Field2,
Field3) VALUES (?, ?, ?)"
Dim InsertCmd As New Data.OleDb.OleD bCommand(strIns ertCmd, MyCNN)
MyDA.InsertComm and = InsertCmd
Dim MyDS As New DataSet
MyDA.Fill(MyDS, "TableName" )
Dim drNew As DataRow
drNew = MyDS.Tables("Ta bleName").NewRo w
drNew.Item("Fie ld1") = "New value" 'string field
drNew.Item("Fie ld2") = 12 'integer
drNew.Item("Fie ld3") = 123 'integer
MyDS.Tables("Ta bleName").Rows. Add(drNew)
MyDA.Update(MyD S, "TableName" ) <------------ the offending code
End Sub
End Class
I'd really like to understand what's going on.
Thanks,
Georges
Comment