Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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 …
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 …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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