Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2008
    Posts
    49

    Unanswered: asp.net connecting to access database

    hi, i have created a database on microsoft access 2003.
    I have created a website in asp.net( visual basic). I have a page on the website where customers can make an order.

    there is a customer table and a order table in my database. The way i have done is is i have created a text box for each attribute and a button. once the fields are filled out and the butoon clicked the records are updated in the database.

    however the problem is i can only enter data into one table. e.g the customer name, address, tel no etc is entered and when buton clicked data is updated in the database. but how can i enter data into 2 diffrent tables at once with the click of one button.

    This is the code that i use to enter data to one table, what i want to do is add data to two tables that are in a relationship:


    imports.......etc

    Public strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("Customer.mdb")

    Protected Sub submit1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit1.Click

    Dim cmd As New OleDbCommand("INSERT INTO Customer(Name,EMailAddress)VALUES('" & name.Text & "','" & email.Text"')", New OleDbConnection(strConn))

    cmd.Connection.Open()
    cmd.ExecuteNonQuery()
    cmd.Connection.Close()
    End Sub



    I would be very greatful for your help and would like to thank you a million in advance.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Keep the connection open, execute 3 differet queries?
    Code:
    Open connection
        execute 1st query
        execute 2nd query
        execute 3rd query
    close connection
    I don't have an internet connection on my development PC at the moment so I can't be much more help than pseudo code at the moment!

    Let us know how you get on
    George
    Home | Blog

  3. #3
    Join Date
    Feb 2008
    Posts
    49

    database connection

    hi, ok i have found out how to insert into different tables,

    you have to execute three commands,

    add data into customer table,

    get the customer id created,

    and then add data into the order table with the retrieved customer id.

    But i do not know how to code this

    i have looked around, and everyone talks about entering data into one table,

    or just retrieving the created id, i really need to know how to code this.

    Your help will be really valued.

    Thank You

    AA

  4. #4
    Join Date
    Feb 2008
    Posts
    49
    anyone know how to do this please, ive searched everywhere but cant find it.

    thankls

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Apologies, I could have sworn I had already responded to this post!


    ...Aparently not, but I have found the reply I meant to have at least linked to

    http://www.dbforums.com/showthread.php?t=1628829
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •