Output parameters for dynamic SQL

  • Thread starter Thread starter Nemisis
  • Start date Start date
N

Nemisis

Hi everyone,

I am saving a record to SQL and want to return the ID of the record
added as an output parameter, can you do this in dynamic SQL, without
the use of a stored procedure??

i.e.

comm = new sqlcommand
comm.commandtext = "Insert (name) values (@name); select @id =
SCOPE_IDENTITY();

' add parameters to command etc

comm.executeNonQuery()

dim a as integer = ctype(comm.parameters.item("@id").value, integer)

Is this possible?? I know you can do it in SQL but we have over 80
databases that this data layer will connect to and i am not one for
duplicate code over each database, just encase one database had a
different version of the sproc for whatever reason.
 
Use executescalar .. the value returned will be the id .. executenonquery
specifies you are not returning a result.

Cheers,

Greg
 
Back
Top