Solved

Writing content of datatable to the database

Posted on 2011-09-23
2
153 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

772 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