c# - How to return the value of Identity element -


i have table in sql server 3 columns id (int identity), email (nvarchar(50)), password (nvarchar(50)). want write query can insert email , password , time, want return identity element id.

for e.g insert abc@dal.ca , password identity element value should returned.

i wrote as:

@email nvarchar(50), @password nvarchar(50), @id int  insert addemail(email, password)  values(@email,@password)  return @id 

is proper ?? how should ? how should check whether working or not ? if select

dbo.sp_addemailreturnid abc@dal.ca, demo 

and click on execute, shows

incorrect syntax near '.'.

i unable find error. trying insert email id , password inserted , identity element automatically incremented 1 every new row.

in code part asp.net, how retrieve id. ?

do this

 private int getemail(string email, string password)   {     string cs = configurationmanager.connectionstrings["dbcs"].connectionstring;     using (sqlconnection conn = new sqlconnection(cs))     {        conn.open();       sqlcommand cmd = new sqlcommand("sp_addemailreturnid", conn);       cmd.commandtype = commandtype.storedprocedure;       cmd.parameters.addwithvalue("@email", email);       cmd.parameters.addwithvalue("@password",password);       int nuploadid = convert.toint32(cmd1.executescalar()); } // updated part 

note

at end of stored proc i.e after insert statement add

select scope_identity() 

edit

your proc sometihng this

alter proc [dbo].[sp_addemailreturnid]       @email                  varchar(500),     @password       varchar(500)         begin  // insert statement here   select scope_identity()  end 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -