Getting primary key after an insert in asp.net (visual basic)

前端 未结 5 818
野的像风
野的像风 2021-01-15 00:39

I\'m adding a record like this:

    Dim pathString As String = HttpContext.Current.Request.MapPath(\"Banking.mdb\")
    Dim odbconBanking As New OleDbConnect         


        
5条回答
  •  Happy的楠姐
    2021-01-15 01:10

    The simplest way would be to generate your uniqueIdentifier value at the code level, add it to your string and send it to the server.

    Dim sql As String, _
        myNewUserId as variant
    
    myNewUserId = stGuidGen    'this function will generate a new GUID value)'
    sql = "INSERT INTO tblUsers ( userId, LastName)" & _
          " VALUES ('" & myNewUserId & "','" & LastName);"
    

    You can check a proposal for the stGuidGen guid generating code here.

    This client-side technique is clear, clean and usefull

提交回复
热议问题