?
Solved

Writing content of datatable to the database

Posted on 2011-09-23
2
Medium Priority
?
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
x77 earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

777 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