i have a stored procedure which pulls the value from column 1 based on the value of column 2. the value from column 1 is then output to the webpage which displays it in a label.
i have input variable bc and output variable fileName. if, for example, i type in 10.00 for the bc value, the fileSymbol spits out the correct value, in this case it's '0'.
if i use 9.00 as the input, the fileSymbol is correct.
if i use 9.7, however, the sproc rounds up to 10 and then gives me the INCORRECT fileSymbol
conversely, if i use 9.3 as the input, the sproc treats this as 9.0 and again, i get the incorrect symbol.
i'm very unsure of how to fix this.
here's my code and thank you for any help...
stored proc:
<pre lang="SQL">
ALTER PROCEDURE getFilename
(
@bc decimal,
@fileSymbol varchar(50) output
)
AS
SELECT @fileSymbol=fileSymbol
FROM tempSymTab
WHERE base = @bc
webpage:
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
codebehind (yes it's sloppy, i'm trying to test and make sure i get the right value first)
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string connSTR = ConfigurationManager.ConnectionStrings["connStr"].ToString();
SqlConnection conn = new SqlConnection(connSTR);
Class1 c1 = new Class1();
SqlCommand cmd = new SqlCommand("dbo.getFileName", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@bc", SqlDbType.Decimal).Value = decimal.Parse(TextBox1.Text);
SqlParameter parm2 = new SqlParameter("@fileSymbol", SqlDbType.VarChar);
parm2.Size = 50;
parm2.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parm2);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
string outputValue = cmd.Parameters["@fileSymbol"].Value.ToString();
Label1.Text = outputValue;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string connSTR = ConfigurationManager.ConnectionStrings["connStr"].ToString();
SqlConnection conn = new SqlConnection(connSTR);
Class1 c1 = new Class1();
SqlCommand cmd = new SqlCommand("dbo.getFileName", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@bc", SqlDbType.Decimal).Value = decimal.Parse(TextBox1.Text);
SqlParameter parm2 = new SqlParameter("@fileSymbol", SqlDbType.VarChar);
parm2.Size = 50;
parm2.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parm2);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
string outputValue = cmd.Parameters["@fileSymbol"].Value.ToString();
Label1.Text = outputValue;
}