Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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