insert using data reader

  • Thread starter Thread starter i love snmp
  • Start date Start date
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
 
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
 
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
 
Back
Top