Results 1 to 10 of 10

Thread: How to figure out unique identifier?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    One of the tables I write some values to has 2 columns. A 'binary' type column, and a 'uniqueidentifier' type colum.

    When I insert a 1 into the binary column, a uniqueidentifier is created based on the number of seconds since midnight...or something to that effect.

    But once I have created this item, I need a way to go back and extract this unique identifier so that I can put this value in some other tables. Trouble is, I have no means of looking this new uniqueidentifier that was just created.

    Does anyone see a way how I can get it? It's been a long day and I'm tired...maybe I'm just not thinking straight.

    If someone can see a way around my problem, I'd be very appreciative.

    Thanks

    dvst8
    Secret to long life:
    Keep breathing as long as possible.

  2. #2
    Addicted Member
    Join Date
    Aug 2000
    Posts
    195
    Hey. I have a similar problem using INSERT INTO statement. but if you are using the AddNew method then it is easy.
    It should look like this

    Set rsRecordset=DB.OpenRecordset(...)

    with rsRecordset
    .AddNew
    .Fields("Binary")=1
    .Update
    'And here is the trick
    .Bookmark=.LastModified
    end with

    Hope that helps. Lastmodified stores the bookmark value of last modified record (in this case the new added record)
    Brandon

  3. #3
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83

    SQL Server ?

    In SQL Server is it possible to make a stored prosedure that do the insert and in the end have something like :

    SELECT @uniqueidentifier = @@Identity

    That returns the identity of the created row.

    You define the uniqueidentifier as firstparameter like :

    @uniqueidentifier int output,
    @BinaryData......
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    AKA
    Not sure...

    Brando

    does addNew do the same as an insert into the database?>?

    Secret to long life:
    Keep breathing as long as possible.

  5. #5
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    AddNew and Insert is the "same". AddNew is ADO and Insert is SQL.

    Do you use SQL Server ?

    Asuming you have a stored procedure named Binary_InsOne simmalar to this example

    Code:
    CREATE PROCEDURE Binary_InsOne
     @GroupId int output,
     @BinaryData binary
    AS
     
    INSERT INTO Binary
     (
     BinaryData
     )
    SELECT
     @BinaryData 
    
    SELECT @uniqueidentifier = @@Identity
    RETURN 0
    Then you could do this in VB

    Code:
        Dim objCmd As New ADODB.Command
    
        On Error GoTo ErrHandler
        With objCmd
            .CommandText = "Binary_InsOne"
            .CommandType = adCmdStoredProc
            .ActiveConnection = dbSqlServer
        End With
        
        With objCmd.Parameters
            .Append objCmd.CreateParameter  ("@uniqueidentifier", adBigInt, adParamOutput, ,uniqueidentifier , )
            .Append objCmd.CreateParameter( "@BinaryData",  adBinary, adParamInput, , BinaryData)
        End With
        
        objCmd.Execute
        
        Set objCmd = Nothing
    ending up with the identifier in your uniqueidentifier varible.
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    thanks AKA!
    Secret to long life:
    Keep breathing as long as possible.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    I'm tyring to do the ADO method, and I get the following error:

    "Object or provider is not capable of performing requested operation."

    I'm just using default cursor, but this should still work...

    dvst8
    Secret to long life:
    Keep breathing as long as possible.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    AKA

    how do I access the output variable from ado?
    and, why do you return 0 in your stored procedure?

    thanks

    [Edited by dvst8 on 08-18-2000 at 10:23 AM]
    Secret to long life:
    Keep breathing as long as possible.

  9. #9
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    You will get the result in your VB variable uniqueidentifier that you sent in with CreateParam.

    The 0 have I inherit and I have always asumed that it is the errorcode being OK, but I dont realy know.
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  10. #10
    Member
    Join Date
    Aug 2000
    Posts
    51
    I had a similar problem. I think I solved it by using the .movelast method on the recordset. Because the record has just been created it is the last one.

    This may or may not work depending on how you connect to the database. I was using ADO 2.1 I think. Whether the recordset contains the identifier depends on how you connect to 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