Change SqlParameter pRI = new SqlParameter("@productRefractiveIndex", SqlDbType.Decimal)
to SqlParameter pRI = new SqlParameter("@
productRI", SqlDbType.Decimal)
--
I do apologise for misreading some of your code. I see it is a decimal so please see my example to fix your issue.
StoredProc:
create procedure [dbo].[getNameId]
@name varchar(256),
@rate decimal(6,4) output
as
select @rate = names.rate from Names where Name = @name
UI:
<div>
Name
<asp:TextBox runat="server" ID="nameTextBox"></asp:TextBox>
<br />
<asp:Button runat="server" ID="getButton" Text="Get data"
onclick="getButton_Click" />
<asp:Label runat="server" ID="returnValueLabel"></asp:Label>
</div>
Code:
protected void getButton_Click(object sender, EventArgs e)
{
string name = nameTextBox.Text;
decimal rate = 0;
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["localTest"].ConnectionString))
{
SqlCommand command = new SqlCommand("dbo.getNameId", connection);
command.CommandType = CommandType.StoredProcedure;
SqlParameter nameParam = new SqlParameter("@name",SqlDbType.VarChar);
nameParam.Size=256;
nameParam.Value = name;
SqlParameter rateParam = new SqlParameter("@rate",SqlDbType.Decimal);
rateParam.Direction = ParameterDirection.Output;
rateParam.Precision = 6;
rateParam.Scale = 4;
command.Parameters.Add(nameParam);
command.Parameters.Add(rateParam);
connection.Open();
command.ExecuteNonQuery();
rate = (decimal)rateParam.Value;
returnValueLabel.Text = rate.ToString();
}
}
Note: on the code line "rate = (decimal)rateParam.Value;" you could also do:
rate = Convert.ToDecimal(rateParam.SqlValue.ToString());
You can access the param.SqlValue also.