Procedure pInsertTempTable has too many arguments specified

coleman8er

New member
Joined
Mar 28, 2008
Messages
1
Programming Experience
3-5
I am getting the error:

SQLException:
Procedure or function pInsertTempTable has too many arguments specified.

However, the stored procedure has exactly eight parameters, and the code has eight as well. I dont know why it saying there are too many. It shows the error upon hitting cmdInsert.ExecuteNonQuery()

Any clues what may be going on here?

VB.NET:
Dim ds As DataSet
Dim dr As DataRow
Dim sqlconn As New SqlConnection(GetConnectionString())
Dim cmdInsert As New SqlCommand("pInsertTempTable", sqlconn)
cmdInsert.CommandType = CommandType.StoredProcedure
ds = FillDataset()
sqlconn.Open()

Try
     For Each dr In ds.Tables(0).Rows
            cmdInsert.Parameters.Add(New SqlParameter((TempTableData.DATE_CURRENTVALUE_PARM), TempTableData.DATE_SQLTYPE)).SourceColumn = ds.Tables(0).Rows.Item(0).ToString
            cmdInsert.Parameters.Add(New SqlParameter((TempTableData.TIME_CURRENTVALUE_PARM), TempTableData.TIME_SQLTYPE)).SourceColumn = ds.Tables(0).Rows.Item(1).ToString
            cmdInsert.Parameters.Add(New SqlParameter((TempTableData.TYPE_CURRENTVALUE_PARM), TempTableData.TYPE_SQLTYPE)).SourceColumn = ds.Tables(0).Rows.Item(2).ToString
            cmdInsert.Parameters.Add(New SqlParameter((TempTableData.REF_CURRENTVALUE_PARM), TempTableData.REF_SQLTYPE)).SourceColumn = ds.Tables(0).Rows.Item(3).ToString
            cmdInsert.Parameters.Add(New SqlParameter((TempTableData.CLASS_CURRENTVALUE_PARM), TempTableData.CLASS_SQLTYPE)).SourceColumn = ds.Tables(0).Rows.Item(4).ToString
            cmdInsert.Parameters.Add(New SqlParameter((TempTableData.NUMBER_CURRENTVALUE_PARM), TempTableData.NUMBER_SQLTYPE)).SourceColumn = ds.Tables(0).Rows.Item(5).ToString
            cmdInsert.Parameters.Add(New SqlParameter((TempTableData.CODE_CURRENTVALUE_PARM), TempTableData.CODE_SQLTYPE)).SourceColumn = ds.Tables(0).Rows.Item(6).ToString
            cmdInsert.Parameters.Add(New SqlParameter((TempTableData.BNUMBER_CURRENTVALUE_PARM), TempTableData.BNUMBER_SQLTYPE)).SourceColumn = ds.Tables(0).Rows.Item(7).ToString

            
    Next
        Catch ex As Exception
        End Try

        cmdInsert.ExecuteNonQuery()
        sqlconn.Close()
 
With the For-loop you're adding 8 identical parameters again and again.
 
You really need to brush up on your data access skills, cause you shouldnt be wriitng that code.. Read the DW2 link in my signature, section on Creating a Simple Data App, and work from there
 

Latest posts

Back
Top