get autoNumber value from database

后端 未结 2 1288
不知归路
不知归路 2021-01-22 17:27

The code is below. in my code I updating existing row(from existing table) that the program get all the updated values from textBoxes. there is at the end(the last column)of the

2条回答
  •  旧时难觅i
    2021-01-22 18:02

    I'd suggest moving the query from inline sql to a stored procedure. Not so much to stop SQL injection but because you can set the stored procedure to return the value of the identity (autonumber) field its just created. simply have it return SCOPE_IDENTITY after running the sql.

    all that is assuming you are using SQL server (I'm not familiar with other db's but would assume they have similar functionality)

    see link for more info

    http://msdn.microsoft.com/en-us/library/ks9f57t0.aspx

    EDIT: WOW this was answered fast! apologies for duplicate answers

    EDIT2: looks like access exposes a variable @@IDENTITY that contains the last used/created autonumber. so you should be able to run and inline query and follow it with another along the lines of 'SELECT @@IDENTITY AS prevID'

提交回复
热议问题