Retrieving Stored Procedures Parameter Info using ADO.NET

 The below code provides way to retrieve meta information about the stored procedure argument

//The usual code
OleDbConnection dbConnection = new OleDbConnection(<Connection string>);
OleDbCommand dbCommand = new OleDbCommand(<sp name>,dbConnection);
dbCommand.CommandType = CommandType.StoredProcedure;

//The FUNCTION
OleDbCommandBuilder.DeriveParameters(dbCommand);

The above static DeriveParameters method retrieve information about stored procedure specified by the command object.

//Iterating over the Parameter and retrieving the meta information….
foreach(OleDbParameter param in discoveredParameters)
{
Console.WriteLine(“Name Of Parameter:{0}”,param.ParameterName);
Console.WriteLine(“Data Type: {0}”,param.OleDbType.ToString());
Console.WriteLine(“Input/Input-Output: {0}”,param.Direction.ToString());
Console.WriteLine(“Size:{0}”,param.Size);
}

Advertisements

4 Responses

  1. Krall

    Useful, thank you!

  2. Search Directory Page

    Thank you for your post!

  3. Hotels and Travel Services in Turkey

    Thank you for your post!

  4. Yahweh’s New Covenant Assembly

    Useful, thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: