Stored Procedure Parameters

G

Guest

I have a stored procedure that takes three input parameters and returns a
single record result set. The stored procedure is declare as follows:

p_getTaxAmount (@ZipCodeDtlId uniqueidentifier, @CategoryID
uniqueidentifier, @SalesAmount decimal(17,8))

I have a windows form where the user enters the zip code, category, and
sales amount. I need to know how to capture the value in the sales amount
text box and send it as a parameter to the stored procedure. I'm very close
but I don't know how to convert the string from the text box to a decimal
value. I keep getting an error message stating "Input string was not in
correct format". My conversion statement is shown below. How do I send the
parameter to the stored procedure so the proc will run with the proper input
parameters?

string strSalesAmt = this.tboxAmount.ToString();
decimal SalesAmount = System.Convert.ToDecimal(strSalesAmt);

this.sqlConnection1.ConnectionString
=ConnectionString.CompanyConnectionString;
this.sqlSelectCommand1.CommandText = "[p_getTaxAmount]";
this.sqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure;
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
false, ((System.Byte)(0)), ((System.Byte)(0)), "",
System.Data.DataRowVersion.Current, null));

this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@ZipCodeDtlID",
System.Data.SqlDbType.UniqueIdentifier));

this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@CategoryID",
System.Data.SqlDbType.UniqueIdentifier));

this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@SalesAmount",
System.Data.SqlDbType.Decimal));

this.sqlSelectCommand1.Parameters["@ZipCodeDtlID"].Value = ZipCodeDtlId;
this.sqlSelectCommand1.Parameters["@CategoryID"].Value = CategoryId;
this.sqlSelectCommand1.Parameters["@SalesAmount"].Value = SalesAmount;
 
G

Guest

Hi Johnny,

If your control tboxAmount is, as its name suggests, a TextBox, then I
suggest you try this:
string strSalesAmt = this.tboxAmount.Text;
decimal SalesAmount = Convert.ToDecimal(strSalesAmt);

or in one line:
decimal SalesAmount = Convert.ToDecimal(tboxAmount.Text);

instead of this:
string strSalesAmt = this.tboxAmount.ToString();
decimal SalesAmount = System.Convert.ToDecimal(strSalesAmt);

HTH,
Sitar.
 

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