none
How do I get value of autogenerated column in MS SQL

    Question

  • I have a table with column with autogenerated values. After I add a new row, how do I get the autogenerated value of the given column of this row?
    Wednesday, November 25, 2009 5:52 PM

Answers

  • Hi,

    For SQL Server Compact related issues, I advise you to post them at  SQL Server Compact forum where you may get quicker and better support.

     

    Thanks,

    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    • Marked as answer by eryang Thursday, December 03, 2009 7:20 AM
    Monday, November 30, 2009 7:04 AM

All replies

  • Set an OutParameter in your stored procedure which inserts the data and access this in your code. this works on Oracle, I am guessing it should also work on SQL server.
    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    Wednesday, November 25, 2009 6:07 PM
  • However I run it with generate table adapter code. What I used to do is to reset table adapter and reload the table table. But this loses all links to the table itself. Is there a simple way with generated code? 
    Wednesday, November 25, 2009 6:14 PM
  • If you are using Identity property to autogenerate value in column, then you can use @@Identity or SCOPE_IDENTITY functions. It will return the last value.

    http://msdn.microsoft.com/en-us/library/aa933167(SQL.80).aspx
    http://msdn.microsoft.com/en-us/library/aa259185(SQL.80).aspx


    Gaurav Khanna
    Wednesday, November 25, 2009 6:16 PM
  • But I need to avoid pure SQL. I am using the following datasource Microsoft SQL Server Compact 3.5 (.NET Framework Data Provider for Microsoft SQL Server Compact 3.5)

    and option "Refresh data table" is disabled


    update:
    looks like Compact server does not support batch updates and there that option is disabled
    Wednesday, November 25, 2009 6:23 PM
  • Hi,

    For SQL Server Compact related issues, I advise you to post them at  SQL Server Compact forum where you may get quicker and better support.

     

    Thanks,

    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    • Marked as answer by eryang Thursday, December 03, 2009 7:20 AM
    Monday, November 30, 2009 7:04 AM