Insert Data to a table with a drop down box

Hi,

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
TAS-ITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

deadlyDevCommented:
Hey,

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();
custDataContext.Invoices.InsertOnSubmit(inv);
custDataContext.SubmitChanges();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.