Insert Data to a table with a drop down box


I have 2 tables, CUSTOMER and INVOICE linked by ID.Customer = CustomerID.Invoice
I want to create a webform where I select the customer from a drop down list box and once the customer is selected, an invoice form pops up with the Customer_ID inserted in the INVOICE table and the remaining INVOICE fields are empty for me to enter in the data.  I am using Visual Studio Express because it require very few programing to generate a form.  I want to use the gui interface as much as possible and keep myself away from hard coding anything in.  I got it
Who is Participating?
deadlyDevConnect With a Mentor Commented:

Step 1.
Add a LinqToSql data mapping to your project (Right click on project -> Add New Item -> Linq To Sql Classes

Step 2.
Connect to your database with the Server Explorer and drag the tables you want onto the LinqToSql designer.

Step 3.
Get the customer data in a manner similar to code snippet 1...

Step 4.
Bind the data to the drop down:
dropDown.DataSource = custData;

Step 5.
Assign the OnSelectedIndexChanged event and add a method to handle it.

Step 6.
In the event method place snippet 2...

You can now get the id of the newly created invoice from the inv instance, and write any values you want to that object, calling custDataContext.SubmitChanges() when done.
//Snippet 1
var custDataContext = new MyLinqDataContext();
var custData = from c in custDataContext.Customers
               select c;
//Snippet 2
var selCust = dropDown.SelectedValue as Customer;
var inv = new Invoice();
inv.CustomerId = selCust.Id;
var custDataContext = new MyLinqDataContext();

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.