Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Writing content of datatable to the database

Posted on 2011-09-23
2
Medium Priority
?
161 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

604 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