Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP.NET and access database

    I am using ASP.NET in visual studio 2005 and am connected to a database. the database has two tables, users and items. The item table has a composite key, made up from username (the prmary key from username table) and item name (Item table primary key).

    i can add a users details to the database, via the code:

    Function InsertUser(ByVal NewUsername As String, ByVal NewTitle As String, ByVal NewSurname As String, ByVal NewForename As String, ByVal NewAddressLine1 As String, ByVal NewAddressLine2 As String, ByVal NewCounty As String, ByVal NewCountry As String, ByVal NewPostcode As String, ByVal NewEmail As String) As Integer

    Dim connectionString As String = _
    "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; " & _
    " Data Source=C:\Documents and Settings\Compaq_Owner\Desktop\WebSite2\App_Data\proto.mdb"

    Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

    Dim querystring As String = "INSERT INTO [tblUser] (Username, Title, Surname, Forename, AddressLine1, AddressLine2, County, Country, Postcode, Email) " & _
    "values (@Username, @Title, @Surname, @Forename, @AddressLine1, @AddressLine2, @County, @Country, @Postcode, @Email)"

    Dim cmd As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
    cmd.CommandText = querystring
    cmd.Connection = dbConnection

    What i need help with is adding an item to the database for a specific user. say the user id was USER1, I need to add a an item to USER1s account, how do i go about directing the item to add to this username?

  • #2
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Add the item name and the username in the item table:

    insert into tblItem (ItemName, Username) values (@ItemName, @Username)

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i want to reference the username from somwhere else. i just want to add the item details and get the username from sumwhere else.


  •  

    Posting Permissions

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