Solved

VB.net insert multiple records into table on insert based on Order Number

Posted on 2009-05-14
1
369 Views
Last Modified: 2012-05-07
I have a table Order_No with Order_No (Auto Increment) and Date Ordered
I also have another table Order with ID, Order_No (Which needs to be populated of the next available number from the Order_No table)

Then I also need to know how to loop through on insert for my Orders table based on ProductID. Each Product has unique values and all items will be tied together by Order_No.  I have done simple inserts into a table before, but never one like this...

help?


Try
 

            Dim insertOrder As New Data.SqlClient.SqlCommand("INSERT INTO Orders(Order_No,AssociationID,Customer_ID,ProductID,Options,Rate,RateOvveride) VALUES (@Order_No,@AssociationID,@Customer_ID,@ProductID,@Options,@Rate,@RateOvveride); SELECT SCOPE_IDENTITY();", myConnection)

            insertOrder.Parameters.AddWithValue("@AssociationID", ddlAssociation.SelectedValue)

            insertOrder.Parameters.AddWithValue("@Customer_ID", ddlExhibitor.SelectedValue)

            insertOrder.Parameters.AddWithValue("@ProductID", txtDirProdID.Text)

            insertOrder.Parameters.AddWithValue("@Options", ddlDirSize.SelectedValue)

   
 

            myConnection.Open()

            insertOrder.ExecuteNonQuery()

            myConnection.Close()
 
 

        Catch ex As Exception
 

            lblConfirmation.Text = "Error saving: " & ex.Message.ToString

        End Try

Open in new window

0
Comment
Question by:Albee_J
1 Comment
 
LVL 8

Accepted Solution

by:
Bob Hoffman earned 500 total points
ID: 24390796
You'd be better off writing a stored procedure to do all this. Execute the stored procedure from your vb.net app. That way all the wrok is executed on the server from a single client-side call.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

9 Experts available now in Live!

Get 1:1 Help Now