SQL sp error

L

Looch

Hi All,

When ever I try the follwoing I get an error message saying too many
arguments specified:

....connection...

sqlCmd.CommandText = "NewCCInf0";
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add("@CustomerID",
SqlDbType.Int);
sqlCmd.Parameters[0].Value = Convert.ToInt16
(txtCustID.Text);
sqlCmd.Parameters.Add("@CardNumber",
SqlDbType.BigInt);
sqlCmd.Parameters[1].Value = Convert.ToInt32
(txtCardNum.Text);
sqlCmd.Parameters.Add("@CardType",
SqlDbType.NChar, 10);
sqlCmd.Parameters[2].Value = cmbType.Text;
sqlCmd.Parameters.Add("@ExpDate",
SqlDbType.DateTime);
sqlCmd.Parameters[3].Value =
txtExpDate.Text.ToString();
sqlCmd.Parameters.Add("@NameOnCard",
SqlDbType.NVarChar, 50);
sqlCmd.Parameters[4].Value = txtNameOnCard.Text;
SqlDataReader reader = sqlCmd.ExecuteReader();
reader.Close();

The sp has the same number of params (I have a vb version of this and
works fine). I've recently switched over to C#, am I missing something
obvious? I commented out the last parameter to give it one less than
needed but still received the same message saying too many arguments.

Help!

Thanks.
 
M

Mike

Try and run SQL Profile on your database and see how many items are being
passed from your code to the proc.
without seeing the proc inputs its hard to say what your missing or adding.
 
L

Looch

Mike, thanks for the suggestion but I'm using SQL 2005 express. I'm
confused though about the error message referencing too many arguments
versus parameters. Are those two definitions interchangable in SQL
2005 and .NET?
 
N

Nicholas Paldino [.NET/C# MVP]

Looch,

Whats the definition of the stored procedure? Can you show the "create
procedrue" command you use to create it?
 
M

Mr. Arnold

Looch said:
Hi All,

When ever I try the follwoing I get an error message saying too many
arguments specified:

...connection...
Maybe, it's something in the data that you're passing that it doesn't like.

Have you tried some dummy data in varibles, nothing fancy with the data,
instead of your controls, just to see what would happen?
 
C

Cor Ligthert [MVP]

Looch,

Can you try it while you have set as first line in this code
sqlCmd.Parameters.Clear();

You will not be the first one who is making this error as that clears it.

Cor
 
B

Bob Johnson

RE: << That worked. Interesting... >>

To explain...

sqlCmd.Parameters is a collection of SqlParameter objects. It contains zero
parameters until you start adding them. After you execute your sqlCommand,
the collection still contains any/all SqlParameter objects (no reason to
automatically clear it). So it's might be a good practice (depending on the
scope of your sqlCommand object) to call the .Clear method prior to
populating the collection to ensure that there aren't any SqlParamter
objects already in it - prior to you adding even more.

-HTH
 

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