AddNew with a GUID - can't get back the GUID 
Author Message
 AddNew with a GUID - can't get back the GUID

Using SQL7 I have a table with a GUID as the key and I need to get back the
value of the GUID immediately after I add a new record. It tells me the
value is {00000.........}, even though if I look in the database my new
record does have a proper GUID value. I am using a dynamic server sided
cursor. Does anyone know how to get the value back?

Thanks



Fri, 26 Dec 2003 09:21:22 GMT  
 AddNew with a GUID - can't get back the GUID
In my test, I am using server side keyset cursor. The Guid field returns
the correct value after Update is called. Below is the code snippet I
tested.

    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim cm As ADODB.Command

    Set cn = New ADODB.Connection
    With cn
        .ConnectionString = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Initial Catalog=test;Data Source=(local)"
        .Open
    End With

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseServer
    rs.CursorType = adOpenKeyset

    rs.Open "select id, gid from guidtest", cn, , adLockOptimistic

    Debug.Print rs.Fields("gid").Value, rs.Fields("id")

    rs.AddNew
    rs.Fields("id") = 4
    rs.Update

    'rs.MoveLast
    Debug.Print rs.Fields("gid").Value, rs.Fields("id")

My platform: ADO 2.5, SQL Server 7. Windows 2000 server. gid is a GUID
field with Default Value equals to (newid()).



Fri, 26 Dec 2003 21:48:36 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. sorry but again: GUID and AUTONUMBER (not GUID only, not AUTONUMBER only, but both)

2. To GUID or not to GUID...

3. How to convert a GUID string to a GUID data type

4. Using a GUID as a Primary Key or indexing a GUID

5. GUID - Reading the GUID of a file

6. Error: 'Malformed GUID in query expression ...'

7. Getting properties via GUID

8. Getting the GUID of an executable

9. Getting an OCX GUID

10. Getting the NIC ID or generating a GUID?

11. Can't .FINDFIRST a GUID???

12. Are GUID's GUARANTEED to be unique?

 

 
Powered by phpBB® Forum Software