1

I have a school project in which I am supposed to build a website using Asp.NET in Visual Studio.

Basically the website is a simple Home Page with links to 5 other pages to display customer data, order data, product data, etc for a company. I have already created a connection between the MS Access database and the website in the Server Explorer in visual studio, and I understand how to use the ListView and Gridview controls to display and update data.

However, I am attempting to update two tables at once using my own update method.

For example, if I wanted to, inside the event handler for a button click, change a customer's CustomerID attribute, the code would change the customerID in the Customer table, and also update the foreign key for customerID in the Orders table, for that specific customer.

Do I need to create a GetConnection method? Would I use SQL queries to accomplish this? Or is there a simpler way to do this?

I'm sorry if this is vague or I am using any incorrect terminology. I am very new to working with databases, but I can answer specific questions about what information I have failed to provide if needed. Thank you!!

I added this statement to the top of the cs file for one of my web pages which should be the correct:

using System.Data.OleDb;

Here is some code I attempted to use, but it's kind of a mess

protected void btnSend_Click(object sender, EventArgs e)
{
    //make this connect to our db
    OleDbConnection conn = new OleDbConnection();
    conn.ConnectionString ="Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\runwayDB1.mdb";
    conn.Open();


    connection.Close();
}
  • 1
    This is a bit too broad a question for this site, but just noting: if I wanted to change a customer's CustomerID attribute, the code would change the customerID in the Customer table, and also update the foreign key for customerID in the Orders table, for that specific customer. - that's quite an advanced scenario. You would need to use a database transaction to ensure that both updates were contained in a database transaction so they must either both complete, or no update is made. – stuartd Apr 15 at 23:05
  • 2
    "if I wanted to...change a customer's CustomerID attribute" Typically you wouldn't change a key value on a record. It's generated when the record is created and doesn't change through the life of that record. One of the reasons being that it starts to get messy when you have foreign key relationships. If you need another value that can be edited, create a separate column for that. – pcdev Apr 15 at 23:05
  • Otherwise, I would say yes, create a connection and write some SQL to do what you need to do. Using controls to display data is a good first step, but actually understanding what is happening 'under the hood' will be helpful in your progress. If you get stuck with the actual SQL you need to write, then ask another question specifically about that! – stuartd Apr 15 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.