|
-
March 2nd, 2010, 08:54 PM
#1
Help with c# arrays, please.
I am familare with arrays from Perl but c# is a new ball game for me. With the help of a few users from this board I recently created an object to handle SQL calls. When I tested it today I got an array error of: CS0225 The params parameter must be a single dimensional array. The line of code is:
public static int ExecNonQuerySP(string SPName, params List<SqlParameter> Params)
Can anyone help me with this as I have no experiance with multi-dimensional arrays and need a bit of help with what is wrong on this. Full code of that object:
public static int ExecNonQuerySP(string SPName, params List<SqlParameter> Params)
{
int RetVal = 0;
using (SqlConnection con = GetCon())
{
SqlCommand cmd = new SqlCommand(SPName, con);
cmd.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter Param in Params)
{
cmd.Parameters.Add(Param);
}
cmd.Connection.Open();
RetVal = cmd.ExecuteNonQuery();
}
return RetVal;
}
-
March 2nd, 2010, 10:43 PM
#2
Re: Help with c# arrays, please.
In the following line:
Code:
public static int ExecNonQuerySP(string SPName, params List<SqlParameter> Params)
The 'params' bit is not required. Try:
Code:
public static int ExecNonQuerySP(string SPName, List<SqlParameter> Params)
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
March 3rd, 2010, 03:29 AM
#3
Re: Help with c# arrays, please.
To elaborate, the 'params' keyword denotes a parameter that is seen from within the function as an array, but from the outside it is a variable length argument list. Example:
Code:
void Foo( params string[] words )
{
foreach( string word in words )
{
Console.WriteLine( word );
}
}
// call it like this
Foo( "one", "two", "three" );
// output
one
two
three
-
March 3rd, 2010, 06:30 AM
#4
Re: Help with c# arrays, please.
That did the trick, thanks for the help and explaination. Now I return you to your regularly schedualed programming.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|