get autoNumber value from database

后端 未结 2 1284
不知归路
不知归路 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条回答
  • 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'

    0 讨论(0)
  • 2021-01-22 18:25

    see this:

    http://msdn.microsoft.com/en-us/library/ks9f57t0(v=VS.80).aspx

    See the section labeled "Retrieving Microsoft Access Autonumber Values"

    sort version

    OleDbCommand cmdNewID = new OleDbCommand("SELECT @@IDENTITY",
                connection)
    

    I do not believe SCOPE_IDENTITY() exist in access

    0 讨论(0)
提交回复
热议问题