Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL and newid()

SQL and newid()

Scheduled Pinned Locked Moved Database
databasequestionannouncement
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael P Butler
    wrote on last edited by
    #1

    I have a table which has a field "ID". The default ID of the field calls the newid() function and generates a GUID. This all works fine. I would like to return the new record ID to my app after adding a record via ADO AddNew. How can I do this. I have tried trying to get the value from the field after the call to AddNew but it returns a VT_EMPTY. I've tried doing it after the Update call but that is also VT_EMPTY. This is the code I'm using, Recordset.Create(); Recordset.Open("calls", *m_pConnection, littleADO::adOpenDynamic,littleADO::adLockOptimistic,littleADO::adCmdTable); variant_t vt; try { Recordset.AddNew(); Recordset.m_pRecordset->Fields->Item["Ref"]->Value = pData->m_sRef.c_str(); Recordset.m_pRecordset->Fields->Item["PoliceForceID"]->Value = pData->m_sPoliceForceID.c_str); Recordset.m_pRecordset->Fields->Item["DivisionID"]->Value = pData->m_sDivisionID.c_str(); Recordset.m_pRecordset->Fields->Item["LocationID"]->Value = pData->m_sLocationID.c_str(); Recordset.m_pRecordset->Fields->Item["CustodyID"]->Value = pData->m_sCustodyID.c_str(); Recordset.m_pRecordset->Fields->Item["CustodyDesc"]->Value = pData->m_sCustodyDesc.c_str(); Recordset.m_pRecordset->Fields->Item["CallTime"]->Value = COleVariant(pData->m_CallTime); Recordset.m_pRecordset->Fields->Item["Status"]->Value = pData->m_nStatus; Recordset.m_pRecordset->Fields->Item["UserName"]->Value = pData->m_sUserName.c_str(); // try and get the id here vt = Recordset.m_pRecordset->Fields->Item["ID"]->Value; Recordset.m_pRecordset->Update(); vt = Recordset.m_pRecordset->Fields->Item["ID"]->Value; } Michael :-)

    M 1 Reply Last reply
    0
    • M Michael P Butler

      I have a table which has a field "ID". The default ID of the field calls the newid() function and generates a GUID. This all works fine. I would like to return the new record ID to my app after adding a record via ADO AddNew. How can I do this. I have tried trying to get the value from the field after the call to AddNew but it returns a VT_EMPTY. I've tried doing it after the Update call but that is also VT_EMPTY. This is the code I'm using, Recordset.Create(); Recordset.Open("calls", *m_pConnection, littleADO::adOpenDynamic,littleADO::adLockOptimistic,littleADO::adCmdTable); variant_t vt; try { Recordset.AddNew(); Recordset.m_pRecordset->Fields->Item["Ref"]->Value = pData->m_sRef.c_str(); Recordset.m_pRecordset->Fields->Item["PoliceForceID"]->Value = pData->m_sPoliceForceID.c_str); Recordset.m_pRecordset->Fields->Item["DivisionID"]->Value = pData->m_sDivisionID.c_str(); Recordset.m_pRecordset->Fields->Item["LocationID"]->Value = pData->m_sLocationID.c_str(); Recordset.m_pRecordset->Fields->Item["CustodyID"]->Value = pData->m_sCustodyID.c_str(); Recordset.m_pRecordset->Fields->Item["CustodyDesc"]->Value = pData->m_sCustodyDesc.c_str(); Recordset.m_pRecordset->Fields->Item["CallTime"]->Value = COleVariant(pData->m_CallTime); Recordset.m_pRecordset->Fields->Item["Status"]->Value = pData->m_nStatus; Recordset.m_pRecordset->Fields->Item["UserName"]->Value = pData->m_sUserName.c_str(); // try and get the id here vt = Recordset.m_pRecordset->Fields->Item["ID"]->Value; Recordset.m_pRecordset->Update(); vt = Recordset.m_pRecordset->Fields->Item["ID"]->Value; } Michael :-)

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      I've changed my code to use a stored procedure which returns the value of the ID back as an output parameter. This works pretty well. I'd still be interested to know if it is possible via AddNew though. Michael :-)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups