Inserting a record and retrieving recordid
-
hi all, Im using Microsoft Data Application Block for this. Im trying to execute a sql procedure that inserts a row. I need to get the identity field (eventID) returned back to me. Ive tried several ways but it wont work. Anyone have a complete example written in c# 1.0 for sql server 8.0, with c# code and stored procedure? Really appreciate all the help. thanks Moazzam
-
hi all, Im using Microsoft Data Application Block for this. Im trying to execute a sql procedure that inserts a row. I need to get the identity field (eventID) returned back to me. Ive tried several ways but it wont work. Anyone have a complete example written in c# 1.0 for sql server 8.0, with c# code and stored procedure? Really appreciate all the help. thanks Moazzam
Why don't you show us your code and we can show you where to put it right? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
-
hi all, Im using Microsoft Data Application Block for this. Im trying to execute a sql procedure that inserts a row. I need to get the identity field (eventID) returned back to me. Ive tried several ways but it wont work. Anyone have a complete example written in c# 1.0 for sql server 8.0, with c# code and stored procedure? Really appreciate all the help. thanks Moazzam
Assuming your table contains an Identity column ..
create procedure EmployeeCreate (@name varchar(20), @dept varchar(20), @employeeid numeric out) as begin insert into Emplyee (Name, Department) values (@name, @dept) select @employeeid = @@identity end
So when you execute your SQL command from .net and pass parameters, pass a parameter for "@employeeid". You wont need to set a value for this SqlParameter, but you'll have to set the correct Direction. - Malhar