[SOLVED] Â Insert record and return new ID as SQL output giving error |
2/21/2019 2:03:26 PM |
ASPRunner.NET General questions | |
P
precisiondi author
I am trying to insert a record into a table and then return the unique ID of the record added. I am using a GUID identifier and not a numeric auto-increment field. |
|
P
|
precisiondi author 2/21/2019 |
I was able to get around this by using the following type of query, which ends with a standard select statement: |
![]() |
Admin 2/21/2019 |
There is an easier and cleaner way to do the same using database API: string sql = String.Format("insert into ...");
|
P
|
precisiondi author 2/21/2019 |
There is an easier and cleaner way to do the same using database API: string sql = String.Format("insert into ...");
|
![]() |
Admin 2/25/2019 |
Tested in ASPRunner.NET 10.0 and it worked string sql = String.Format(@"INSERT INTO tests (name) values ('test@test.com')");
|
P
|
precisiondi author 3/8/2019 |
This works up until I modify the database to not use integer unique identifiers but choose instead to use UNIQUEIDENTIFIER data types for the tables unique id column. |
![]() |
Pete K 3/12/2019 |
This works up until I modify the database to not use integer unique identifiers but choose instead to use UNIQUEIDENTIFIER data types for the tables unique id column.
|
P
|
precisiondi author 3/12/2019 |
Are you forced to use UNIQUEIDENTIFIER? Because it is not possible to retrieve this after insert. Things work much better with an int type. See: https://www.sqlteam.com/articles/uniqueidentifier-vs-identity
|