Returning a cursor from a stored procedure

A

arne

How do I capture a resultset from a stored procedure with
ado.net code?

ALTER PROCEDURE dbo.sp_ins_contacts
(
@FName nvarchar(50),
@LName nvarchar(50),
@Initials nvarchar(50),
@IntakeDate smalldatetime,
@SSN nchar(10),
@Advisor nvarchar(50 )
AS
SET NOCOUNT OFF;
INSERT INTO tbl_Contacts(FName, LName, Initials,
IntakeDate, SSN, Advisor) VALUES (@FName, @LName,
@Initials, @IntakeDate, @SSN, @Advisor);
SELECT ContactID, FName, LName, Initials,
IntakeDate, SSN, Advisor FROM tbl_Contacts WHERE
(ContactID = @@IDENTITY)
 
K

Kevin Yu

Hi Arne,

The SqlCommand class can help. You can use it together with the
SqlDataAdapter class. Set the SqlCommand's command type to
CommandType.StoredProcedure and bind it to a SqlDataAdapter, and then you
can fill the query result into a dataset. Here is a code snippet for sample:

SqlConnection sqlcnn = new SqlConnection("<Your connection string here.>");

SqlCommand sqlcom = new SqlCommand();

sqlcom.CommandType = CommandType.StoredProcedure;

sqlcom.CommandText = "dbo.sp_ins_contacts";

sqlcom.Connection = sqlcnn;

SqlDataAdapter sda = new SqlDataAdapter(sqlcom);


DataSet ds = new DataSet();

sda.Fill(ds);

Does this answer your question? If there is anything unclear, please reply
to this post.

Kevin Yu
========
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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