Stored procedures

A

Ann Marinas

Hi, all!

I would like to ask a favor regarding ADO.NET...

I would like to know how I can access programmatically stored procedures in
a SQL Server. I've been pulling my hair up all weekend, and it seems that I
couldn't get it.

Thanks!
 
D

Dishan

create
this.m_oCommand = new SqlCommand( sStoredProcedureName );

// Set Command Type to StoredProcedure Command

this.m_oCommand.CommandType = CommandType.StoredProcedure;

Add parameters

oParam = new SqlParameter( "@abc", SqlDbType.Bit );

oParam.Direction = ParameterDirection.Input;

oParam.Value = true;

oSProc.AddParameter( oParam );

// Add the return value parameter( for return value)

SqlParameter param = m_oCommand.Parameters.Add( "RETURN_VALUE",
SqlDbType.Int );

param.Direction = ParameterDirection.ReturnValue;

and run command using ExecuteNonQuery. It'll return SqlParameterCollection

Regards

Dishan
 
M

Marc Scheuner [MVP ADSI]

I would like to know how I can access programmatically stored procedures in
a SQL Server. I've been pulling my hair up all weekend, and it seems that I
couldn't get it.

1) Drop a SqlConnection on your form, and hook it up to your SQL
database

2) Drop a SqlCommand on your form, set the Connection property to the
above connection, set the CommandType to
"CommandType.StoredProcedure", set CommandText to the stored procedure
name (e.g. "MyStoredProc"), and define the parameters the procedure
has in the "Parameters" property

3) Open the connection, and then either use a SqlDataAdapter to fill a
DataTable with the output from your stored proc, or execute your
stored proc (if it doesn't return a result set).

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 

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