Results 1 to 13 of 13

Thread: Bloody Access Database

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Exclamation Bloody Access Database

    Hey people stupid one here
    I dont think access datbase supports @@Indentity
    so there fore i need toknow whats the best way to reteive the recordID that ive just added to the db, i am useing access querys

    cheers peps

    Carl
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I am afriad you have to requery the database to know what was the newest record added. I use AutoNumber fields when I just want to have a primarykey, otherwise when it comes to caring for the number of record or such, I use a number field whose value is determined by the code and I know beforehand what I am going to put into it.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can use MSDE instead, its like SQL Jr.

  4. #4

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    dont really want to use SQL
    i guess theres no fancy way to do this i saw the other day some like select max(recordId) or something like that????
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  6. #6
    Member
    Join Date
    May 2001
    Posts
    39
    Since the 2000 version Access supports @@Indentity.

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by Desbaratizador
    Since the 2000 version Access supports @@Indentity.
    Thanks
    In fact 'Jet OLE DB Provider Version 4.0 Supports SELECT @@Identity'
    http://support.microsoft.com/default...NoWebContent=1
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  8. #8

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    Jet OLE DB Provider Version 4.0 Supports SELECT @@Identity'
    http://support.microsoft.com/defaul...;NoWebContent=1

    Can this be used in VB.Net Application ??? that code looks like normall ASP to me ?
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I never know this before so I've tried it myself and created a demo that you may have a look at it but it has little bug which is : the result I get all zeros I don't know why . Maybe the syntax is incorrect for the sqlstring . But at least you keep testing on this little buggy progy . . It's VB.NET 2003 with XP Database mdb .
    Attached Files Attached Files

  10. #10

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    Priate, ive found this in the MSDN Lib
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconretrievingidentityorautonumbervalues.htm

    Expains everyting to get your code working correct
    I think you need to add or update the table before recovering the identity

    If u get your code working can you post it up

    Cheers Carl
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I tried that and still getting 0 when quering autoincrement field . I don't know what I'm missing here . Here's the updated version of the demo .
    Attached Files Attached Files

  12. #12

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    Prirate your code works mate just fine

    Only thing your fogetting to do is insert or update a record first,
    just copy

    Dim cmdStr As String = "SELECT @@Identity"
    Dim cmdid As New OleDbCommand(cmdStr, MyConnection)
    Dim ident As Integer = Int(cmdid.ExecuteScalar())
    MsgBox("New Ident is: " & ident)

    into any project where your inserting or update just after the commit

    it will return the correct value

    cheers for the help buddy
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  13. #13
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thanks for testing . . I was too lazy to add in the database ...

Posting Permissions

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



Click Here to Expand Forum to Full Width