Solved

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

Posted on 2009-05-14
1
370 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

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

937 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

10 Experts available now in Live!

Get 1:1 Help Now