No value given for one or more required parameters.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Georges

    #1

    No value given for one or more required parameters.

    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


  • Cor Ligthert [MVP]

    #2
    Re: No value given for one or more required parameters.

    Georges,

    Have a look at this page how to do it. (You need only 4 lines)



    I hope this helps,

    Cor



    "Georges" <gdufresn@video tron.ca> schreef in bericht
    news:KMb6g.6618 5$hR6.571498@we ber.videotron.n et...[color=blue]
    > 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
    >[/color]


    Comment

    Working...