insert using data reader

I

i love snmp

Guys,

I have a stored procedure in SQL Server where I pass few parameters
like username, email address etc. The stored procedure simply inserts
these records into users table that has an identity column as ID.
Finally I read the @@IDENTITY variable to read the ID of newly
inserted record and returns it via an OUT parameter passed in the
stored procedure.

Now question is if I have to call this stored procedure from my C#
code, can I used DataReader for this purpose? What are the best
practices?

TIA
imak
 
G

Grzegorz Danowski

U¿ytkownik "i love snmp said:
Guys,

I have a stored procedure in SQL Server where I pass few parameters
like username, email address etc. The stored procedure simply inserts
these records into users table that has an identity column as ID.
Finally I read the @@IDENTITY variable to read the ID of newly
inserted record and returns it via an OUT parameter passed in the
stored procedure.

Now question is if I have to call this stored procedure from my C#
code, can I used DataReader for this purpose? What are the best
practices?

In my opinion the best way is to use ExecuteNonQuery method, and Output
parameters, for example read code snippet in message Eugene Banks "Output
param set to DBNull" (
Regards,
Grzegorz
 
G

Guest

hi

Do it like this to return values using OUT parameter

SqlParameter param=new SqlParameter ("@ret",SqlDbType.Int,8);
param.Direction =ParameterDirection.Output ;
param.Value =-1;
cmd.Parameters.Add(param) ;

cmd.ExecuteNonQuery();


regards

Ansil
Technopark
Trivandrum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top