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

前端 未结 5 780
野的像风
野的像风 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条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-15 01:11

    You'll want to add

    ;select scope_identity();
    

    after your query, and run executeScalar to get the value back.

    Also, on a completely unrelated note, you really should change your code to use parameterized queries so you don't get caught with SQL injection attacks, or crashes due to inproperly escaped strings concatenated into your sql statement.

提交回复
热议问题