Re: Use ExecuteScalar to return identity or Guid newID?
- From: Clint Hill <clint.hill@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Jul 2005 13:57:45 -0700
Actually, you will probably need to run two commands to get it done. Keep your connection open for both and use it in both.
psuedo code:
SqlConn.Open()
InsertCommand.Execute(SqlConn) -- using your insert statement
int id = IdCommand.Execute(SqlConn) -- using either scope_identity or @@identity
SqlConn.Close()
Clint Hill H3O Software http://www.h3osoftware.com
eagle wrote:
How can I return the new id that is created when an insert command is used? for example:
qry = "insert into tblClients (lname, fname) values ('smith', 'joe')" Dim xyz as string = command.executescalar(strconn, commandtype.text, qry)
I tried this and received an error "System.NullReferenceException: Object reference not set to an instance of an object"
Although the insert does take place. How would I do this? I can't create a stored procedure for this for various reasons.
.
- Follow-Ups:
- References:
- Prev by Date: Adding header to request in HTTP Module
- Next by Date: Re: System.IO.Directoryinfo throwing exception
- Previous by thread: Re: Use ExecuteScalar to return identity or Guid newID?
- Next by thread: Re: Use ExecuteScalar to return identity or Guid newID?
- Index(es):
Relevant Pages
|