I have a stored procedure in SQL Server 2005 which accepts few parameters of type BigInt and Number(18,2).
There is a column ApprovedAmount in the database table of type: Number(18,2).
While calling this stored procedure from C# (VS-2005), I am using code like:
SQLCommand cmd = new SQLCommand(Query, CN)
cmd.Parameters.AddWithValue("ApprovedAmount",txtApprovedAmount.Text);
The above parameter line gives error: Cannot convert from String to Numeric..
I find it painful to write the above line as below because there are so many parameters to pass:
cmd.Parameters.AddWithValue("ApprovedAmount", Convert.ToDouble(txtApprovedAmount.Text));
Is there any easy way to pass parameters so that they are automatically converted to the appropriate database table type in either Stored Procedure itself or with C# code?
I also want to handle a condition that if the TextBox was left blank, the parameter value should be passed as null.
Instead of cmd.Parameters.AddWithValue(), use