Solved

Writing content of datatable to the database

Posted on 2011-09-23
2
152 Views
Last Modified: 2012-05-12
I am trying to write the content of a data table back to a SQL Server table.  It writes the first row, but on the second row, I get following error:

"Procedure or Function InsertHospitalInvoice has too many arguments specified."

I have reviewed everything and I cannot see why I am getting this error.  Below is my code to call the stored procedure InsertHospitalInvoice.  I've also provided a copy of the table design as well the Stored Procedure InsertHospitalInvoice in the attached word document.  

Can anyone see where my bug is.  Your help is greatly appreciated,  Thank you stored-procedure-and-Table-desig.doc
Sub InsHospInvData()
        Dim cmdData As New SqlCommand()

        Try
            conn.Open()
            cmdData.Connection = conn
            For Each drow In dtHospInvData.Rows
                cmdData.CommandText = "InsertHospitalInvoice"
                cmdData.CommandType = CommandType.StoredProcedure
                cmdData.Parameters.AddWithValue("@HID", drow.Item("HID"))
                cmdData.Parameters.AddWithValue("@DeptCode", drow.Item("DeptCode"))
                cmdData.Parameters.AddWithValue("@BillDate", drow.item("BillDate"))
                cmdData.Parameters.AddWithValue("@InTests", drow.item("InTests"))
                cmdData.Parameters.AddWithValue("@InAmount", drow.item("InAmount"))
                cmdData.Parameters.AddWithValue("@OutTests", drow.item("OutTests"))
                cmdData.Parameters.AddWithValue("@OutAmount", drow.item("OutAmount"))
                cmdData.Parameters.AddWithValue("@OtherTests", drow.item("OtherTests"))
                cmdData.Parameters.AddWithValue("@OtherAmount", drow.item("OtherAmount"))
                cmdData.Parameters.AddWithValue("@SvDesc", drow.Item("SvDesc"))
                cmdData.ExecuteNonQuery()
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            conn.Close()
        End Try
    End Sub

Open in new window

0
Comment
Question by:kshumway
2 Comments
 
LVL 15

Accepted Solution

by:
x77 earned 500 total points
ID: 36588062
For first row, the cmdData has 10 parameters- Ok
For second row, you add aditional parameters.

Use cmdData.Parameters.Clear after cmdData.ExecuteNonQuery()
0
 

Author Closing Comment

by:kshumway
ID: 36588091
You are a lifesaver.  Thank you so much.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Clone Visual studio 2013 solution 5 24
Make a border less form movable 2 22
VB.Net - Oracle BulkCopy from CSV Date Format 7 45
Programmatically signing Word macros 4 61
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now