none
one or more required parameter missing RRS feed

  • Question

  • Hello,

    Im trying to insert new rows in Access 2003 using VB 2008. I am getting an error "one or more required parameter missing"

    Below is the code...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim oleconn As New OleDb.OleDbConnection
            oleconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\kaivalya.canay\My Documents\MIS PROJECT\MIS PROJECT 1.mdb;User ID=admin"
            Try
                oleconn.Open()
            Catch oleex As Exception
                MsgBox(oleex.Message, "Connection Error!")
            End Try

            If oleconn.State = 1 Then
                Me.Text = "Welcome to ADO.NET"
            End If

            Dim olecomm As New OleDb.OleDbCommand
            Dim olecomm2 As New OleDb.OleDbCommand

            olecomm.Connection = oleconn
            olecomm.CommandText = "SELECT * FROM loginfo"
            olecomm2.CommandText = "INSERT INTO loginfo (logid,Entity,SECS,Name,IncomeType,Product,Service,DisputeType,InvoiceNo) VALUES (@logid,@Entity,@SECS,@Name,@IncomeType,@Product,@Service,@DisputeType,@InvoiceNo)"

            Dim ds As New DataSet
            Dim da As New OleDb.OleDbDataAdapter

            da.SelectCommand = olecomm

            Dim scb As New OleDb.OleDbCommandBuilder(da)

            Try
                da.Fill(ds, "loginfo")

                Dim ndr = ds.Tables("loginfo").NewRow

                ndr("logid") = TextBox1.Text
                ndr("entity") = TextBox2.Text
                ndr("SECS") = TextBox3.Text
                ndr("Name") = TextBox4.Text
                ndr("IncomeType") = TextBox5.Text
                ndr("Product") = TextBox6.Text
                ndr("Service") = TextBox7.Text
                ndr("DisputeType") = TextBox8.Text
                ndr("InvoiceNo") = TextBox9.Text

                ds.Tables("loginfo").Rows.Add(ndr)

                olecomm2.Parameters.Add("@logid", OleDb.OleDbType.VarChar, 10, "logid")
                olecomm2.Parameters.Add("@Entity", OleDb.OleDbType.VarChar, 10, "Entity")
                olecomm2.Parameters.Add("@SECS", OleDb.OleDbType.VarChar, 10, "SECS")
                olecomm2.Parameters.Add("@Name", OleDb.OleDbType.VarChar, 50, "Name")
                olecomm2.Parameters.Add("@IncomeType", OleDb.OleDbType.VarChar, 10, "IncomeType")
                olecomm2.Parameters.Add("@Product", OleDb.OleDbType.VarChar, 10, "Product")
                olecomm2.Parameters.Add("@Service", OleDb.OleDbType.VarChar, 10, "Service")
                olecomm2.Parameters.Add("@InvoiceNo", OleDb.OleDbType.VarChar, 15, "InvoiceNo")

                da.InsertCommand = olecomm2
               
                da.Update(ds, "loginfo")
               
                MsgBox("Dispute Registered with Log ID " & TextBox1.Text)

                oleconn.Close()

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    End sub

    If i remove the InvoiceNo column from the INSERT statement the data is getting inserted in the database.

    Thanks in advance.
    Tuesday, September 22, 2009 1:03 PM

Answers

  • One addition to Paul's post. After you add missing parameter to the code, you might start to get another error similar to "Syntax error .....". You have some of the column names which use reserved words, like NAME. I would recommend to put all the column names inside of the SQL statement into the square bracket.s The code for it would look like

    olecomm2.CommandText = "INSERT INTO loginfo ([logid],[Entity],[SECS],[Name],[IncomeType],[Product],[Service],[DisputeType],[InvoiceNo]) VALUES (@logid,@Entity,@SECS,@Name,@IncomeType,@Product,@Service,@DisputeType,@InvoiceNo)"


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Zhipeng Lee Monday, September 28, 2009 1:29 AM
    Wednesday, September 23, 2009 10:32 AM
    Moderator

All replies

  • I only see eight parameters in your collection. Looks like DisputeType has not been added.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, September 22, 2009 1:57 PM
  • One addition to Paul's post. After you add missing parameter to the code, you might start to get another error similar to "Syntax error .....". You have some of the column names which use reserved words, like NAME. I would recommend to put all the column names inside of the SQL statement into the square bracket.s The code for it would look like

    olecomm2.CommandText = "INSERT INTO loginfo ([logid],[Entity],[SECS],[Name],[IncomeType],[Product],[Service],[DisputeType],[InvoiceNo]) VALUES (@logid,@Entity,@SECS,@Name,@IncomeType,@Product,@Service,@DisputeType,@InvoiceNo)"


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Zhipeng Lee Monday, September 28, 2009 1:29 AM
    Wednesday, September 23, 2009 10:32 AM
    Moderator