?
Solved

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

Posted on 2009-05-14
1
Medium Priority
?
380 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

830 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