Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to call a Sproc with parameters.
Message
From
23/12/2004 16:16:14
 
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00971830
Message ID:
00971932
Views:
15
Angie,

Seems strange to pass an array of Parameters rather than just a ParameterCollection, but if that's what is being passed, then you could try something like this (untested code):
public int ExecuteScalar(string storedProcedureName, System.Data.SqlClient.SqlParameter[] parameters)
{
    SqlCommand sc = new SqlCommand(storedProcedureName, MyConnection);
    sc.CommandType = CommandType.StoredProcedure;
    for (int i=0; i < parameters.length; i++)
    {
        sc.Parameters.Add(parameters[i]);
    }
    return (int)sc.ExecuteScaler();
~~Bonnie

>Hello everyone,
>
>I have been asked to implement the following signature :-
>
>
>public int ExecuteScalar(string storedProcedureName, System.Data.SqlClient.SqlParameter[] parameters)
>{
>
>}
>
>
>I presume that the SqlParameter array must be populated in the calling code. The task is to create five records in a SQL database with four columns. Could anyone give me an example of how to create the calling code that builds up the SqlParameter array parameter?
>
>This is an example of the sproc,
>
>
>dbo.InsertEmployee 'HARRISON', 'ANGIE', 'PROGRAMMER', 'IT'
>
>
>Assuming that I get the array passed into the ExecuteScalar method, how do you you call the SQLCommand so that the array is used?
>
>I know I am asking a lot but I have looked through the help all day and I cannot find anything that explains how to do this?
>
>Thank you so much!
>
>Angie.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform