C# Winforms - SQL Server 2005 stored procedure - parameters from TextBox

Posted by Geo Ego on Stack Overflow See other posts from Stack Overflow or by Geo Ego
Published on 2010-04-28T19:46:57Z Indexed on 2010/04/28 19:57 UTC
Read the original article Hit count: 1027

I'm trying to call a parameterized stored procedure from SQL Server 2005 in my C# Winforms app. I add the parameters like so (there are 88 of them):

cmd.Parameters.Add("@CustomerName", SqlDbType.VarChar, 100).Value = CustomerName.Text;

I get the following exception:

"System.InvalidCastException: Failed to convert parameter value
 from a TextBox to a String. ---> System.InvalidCastException:
 Object must implement IConvertible."

The line throwing the error is when I call the query:

cmd.ExecuteNonQuery();

I also tried using the .ToString() method on the TextBoxes, which seemed pointless anyway, and threw the same error. Am I passing the parameters incorrectly? Thanks for the help.

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about c#