How to add next larger number to a mdb table as record are added ?

Last post 07-03-2008 10:43 PM by hkbeer. 9 replies.

Sort Posts:

  • How to add next larger number to a mdb table as record are added ?

    07-02-2008, 11:04 PM
    • Loading...
    • hkbeer
    • Joined on 07-03-2008, 12:07 AM
    • Posts 153

    I have a Formview on ASP page that insert records to mdb file.

    Eg the table has 2 col: ID, Name

    I want the ID field to be automatically be populated as the next largest number on the existing ID values when I add  record via FormView.

    Eg the table now has 2 rows

    1, John
    2, Mary

    I want FormView only display Name field when keying in and inserting record but oninsert, it add value of 3 (ie max of existing +1) and save to ID filed as user insert record of the names.

    What is the syntax of max +1 and where to put it ?

    Thanks

  • Re: How to add next larger number to a mdb table as record are added ?

    07-02-2008, 11:10 PM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 7,702
    • Moderator
      TrustedFriends-MVPs

    If you set the ID column in your access db to be an AutoNumber field type, then it will increment automatically.

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: How to add next larger number to a mdb table as record are added ?

    07-02-2008, 11:14 PM
    • Loading...
    • hkbeer
    • Joined on 07-03-2008, 12:07 AM
    • Posts 153

    Thanks. Yes but I also need to delete the records on ASP gridview and setting it to autonumber would causes error in deleting.

     

    I tried to write this script and there is an error. How to do it ? Thanks

    Protected Sub AccessDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
            e.Command.Parameters("ID").Value = Val(SELECT max(ID) FROM TableA)+1

    End Sub

     

  • Re: How to add next larger number to a mdb table as record are added ?

    07-03-2008, 2:11 AM
    • Loading...
    • hkbeer
    • Joined on 07-03-2008, 12:07 AM
    • Posts 153

    Any expert can help ?

     

  • Re: How to add next larger number to a mdb table as record are added ?

    07-03-2008, 2:22 AM

    hkbeer:
    Yes but I also need to delete the records on ASP gridview and setting it to autonumber would causes error in deleting.
     

    That doesn't make any sense.  There should be no error as a result of using the autonumber feature.  What error do you get? Perhaps we can solve that?  Using MAX(ID) + 3 (or similar) will cause problems if two people are inserting at the same time.

     

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: How to add next larger number to a mdb table as record are added ?

    07-03-2008, 4:40 AM
    • Loading...
    • hkbeer
    • Joined on 07-03-2008, 12:07 AM
    • Posts 153

    In fact if I make that ID as autonumber, when inserting record through FormView, I get this error message

    System.Data.OleDb.OleDbException: You tried to assign the Null value to a variable that is not a Variant data type.

     Seems autonumber only works in inserting record within Access but not from ASP page control ?

     

  • Re: How to add next larger number to a mdb table as record are added ?

    07-03-2008, 6:38 AM
    • Loading...
    • hkbeer
    • Joined on 07-03-2008, 12:07 AM
    • Posts 153

    Anyone can help ?
    Or, anyone use Autonumber with no problem including deleting records through Gridview?

  • Re: How to add next larger number to a mdb table as record are added ?

    07-03-2008, 4:20 PM
    Answer

     

    hkbeer:
    System.Data.OleDb.OleDbException: You tried to assign the Null value to a variable that is not a Variant data type.

    I suspect that the ID column is included in the InsertCommand and/or there is a parameter for this field.  Delete them boith.

     

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: How to add next larger number to a mdb table as record are added ?

    07-03-2008, 8:05 PM
    • Loading...
    • hkbeer
    • Joined on 07-03-2008, 12:07 AM
    • Posts 153

    Thanks Mike, yes I have added that in insert or delete parameters. By default it is there. ok I will try deleting them. Thanks again Mike. Great !

     

  • Re: How to add next larger number to a mdb table as record are added ?

    07-03-2008, 10:43 PM
    • Loading...
    • hkbeer
    • Joined on 07-03-2008, 12:07 AM
    • Posts 153

    Hi Mike, it works !! Thanks !!

     

     

Page 1 of 1 (10 items)
Microsoft Communities
Page view counter