Hi,
I am currently developing a C#/ASP.NET web application that hooks into an MSSQL 2005 Express database (will be using 2005 enterprise in the live environment).
The database uses several tables with simple index columns which auto increment (the reason I went for simple integer index values is due to a requirement by the user whereby we need to display the records and their corresponding index number for referencing later on).
I am using the following SQL to return the current maximum value:
SELECT MAX(indexcolumn) FROM mydbtable
I am then adding 1 to the returned value to get the next record id. I need to obtain this value prior to doing any inserts.. which I seem to think is not so easy with MSSQL unless you do a insert first!
I want to be able to find out what the increment value is either by querying the MSSQL database or using some code logic to determine what the correct next id is.
I also have the problem of multiple inserts getting the same index value however I was hoping this is simply a case of letting the database handle the auto increment for each insert and then just updating the posting page with whatever id has been assigned to the record that was just inserted.
Is there a better way of doing this (and simpler as I may be over complicating th matter)?
Thanks in advance,
Fz
I am currently developing a C#/ASP.NET web application that hooks into an MSSQL 2005 Express database (will be using 2005 enterprise in the live environment).
The database uses several tables with simple index columns which auto increment (the reason I went for simple integer index values is due to a requirement by the user whereby we need to display the records and their corresponding index number for referencing later on).
I am using the following SQL to return the current maximum value:
SELECT MAX(indexcolumn) FROM mydbtable
I am then adding 1 to the returned value to get the next record id. I need to obtain this value prior to doing any inserts.. which I seem to think is not so easy with MSSQL unless you do a insert first!
I want to be able to find out what the increment value is either by querying the MSSQL database or using some code logic to determine what the correct next id is.
I also have the problem of multiple inserts getting the same index value however I was hoping this is simply a case of letting the database handle the auto increment for each insert and then just updating the posting page with whatever id has been assigned to the record that was just inserted.
Is there a better way of doing this (and simpler as I may be over complicating th matter)?
Thanks in advance,
Fz