Re: Use ExecuteScalar to return identity or Guid newID?

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.


.



Relevant Pages

  • Re: Use ExecuteScalar to return identity or Guid newID?
    ... Clint Hill ... eagle wrote: ... stored procedure for this for various reasons. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Divine command and moral value in Judaism
    ... The gods might have their reasons for loving what they love ... If we choose to accept their commands as being ... No one questions the existence of morality ... these commands would only become morally binding ...
    (soc.culture.jewish.moderated)
  • Re: Read .htm/.txt file in one field, one record
    ... The whole file must go in the first record, using a command in a stored ... How do I do this using commands in a stored procedure in T-SQL only? ... sample T-SQL statement to do the above. ...
    (microsoft.public.sqlserver.programming)
  • Re: Divine command and moral value in Judaism
    ... The gods might have their reasons for loving what they love ... If we choose to accept their commands as being ... be justified merely by an appeal to authority, ... slow on the uptake) - he's a self-styled legal expert, ...
    (soc.culture.jewish.moderated)
  • Re: DBC Stored Procedure
    ... The code in the stored procedure can only use commands and functions that ... They are listed in the VFP documentation. ... >> Tip When you are using ADO or ADO.NET and setting the Command Type ...
    (microsoft.public.fox.vfp.dbc)