Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005

    Unanswered: database question

    Ive got an access database with a autonumber acting as a customer id.All the connections are working fine with the application.

    When i add a row to the database how do i find out what their customer id is I.E what autonumber im currently adding data to?So the customer knows what their id is...

    the code im using to add a row is

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

    'adding data to the dataset

    'add procedure
    Dim objRow As DataRow

    objRow = objDataSet.Tables("tblCust").NewRow()
    objRow("fname") = txtFname.Text
    objRow.Item("sname") = txtSname.Text
    objRow.Item("address1") = txtAddress1.Text
    objRow.Item("address2") = txtAddress2.Text
    objRow.Item("address3") = txtAddress3.Text
    objRow.Item("email") = txtEmail.Text
    objRow.Item("phone") = txtPhone.Text
    objRow.Item("id") = id
    objRow.Item("trips") = 0
    objRow.Item("spent") = 0
    objRow.Item("card") = cboCardType.Text
    objRow.Item("card_no") = txtCardNo.Text


    objCustDA.Update(objDataSet, "tblCust")


    Retrieve() 'fills the dataset with the new info

    MsgBox("Database changes made", MsgBoxStyle.Information, "Database Modification")

    Any help would be great.

    Last edited by vancottier; 02-07-06 at 09:39.

  2. #2
    Join Date
    Jun 2004
    Arizona, USA
    Not sure if this will work with .Net, but, immediately after adding the row, using the same connection, issue a "Select @@Identity as ID From TableName" & check the value of rs.Fields!ID
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert

  3. #3
    Join Date
    Oct 2004

    Here it is.

    If you are using Autonumber for each record, access will create a unique id number for each record. Now if you want to know what is the Id number of the customer, all you have to do is to create a procedure to retrieve the last added rows and then display the ID num.

    Hope this will help.

Posting Permissions

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