Thursday, March 8, 2012

Cant Remember how to pass int value to datasource

I have know this error but have completely forgotten how to take care of it. How do I pass the integer values to the SQL statement?

ERROR: Syntax error converting the nvarchar value 'Label' to a column of data type int.

WHERE (LinkInfo.L_State = @.State) AND (LinkInfo.CG_ID > @.CatIDLow) AND (LinkInfo.CG_ID > @.CatIDHigh)

<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="State" PropertyName="Text" />
<asp:ControlParameter ControlID="Label2" DefaultValue="0" Name="CatIDLow" PropertyName="Text" />
<asp:ControlParameter ControlID="Label3" DefaultValue="1899" Name="CatIDHigh" PropertyName="Text" />
</SelectParameters>

CODE BEHIND

public partial class TopandBottomSelect : System.Web.UI.Page
{
int CG_IDlower;
int CG_IDupper;

protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
CG_IDlower = 0;
CG_IDupper = 1900;
Label1.Text = Convert.ToString(CG_IDlower);
Label2.Text = Convert.ToString(CG_IDupper);
}
else
{
CG_IDlower = 1899;
CG_IDupper = 3000;
Label1.Text = Convert.ToString(CG_IDlower);
Label2.Text = Convert.ToString(CG_IDupper);
}
GridView1.DataBind();
}
}

Thank you

Add the datatype to the Parameter declarations:

<asp:ControlParameter ControlID="TextBox1" Name="State" PropertyName="Text"Type="Int32" />

|||

The state value is not the problem, just the CatID High and low. I have tried the below with no success.

NEW EDITED CODE Below - same error

ERROR: Input string was not in a correct format.

WHERE (LinkInfo.L_State = @.State) AND (LinkInfo.CG_ID > @.CatIDLOW) AND (LinkInfo.CG_ID < @.CatIDHIGH)">

<asp:ControlParameter ControlID="Label2" Name="CatIDLow" PropertyName="Text" Type="Int32" />
<asp:ControlParameter ControlID="Label3" Name="CatIDHigh" PropertyName="Text" Type="Int32" />

with this Code Behind:

int CG_IDlower;
int CG_IDupper;
int CatIDLOW;
int CatIDHIGH;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
CG_IDlower = 0;
CG_IDupper = 1900;
Label2.Text = Convert.ToString(CG_IDlower);
Label3.Text = Convert.ToString(CG_IDupper);

CatIDLOW = Convert.ToInt32("Label2.Text");
CatIDHIGH = Convert.ToInt32("Label3.Text");
}
else
{
CG_IDlower = 1899;
CG_IDupper = 3000;
Label2.Text = Convert.ToString(CG_IDlower);
Label3.Text = Convert.ToString(CG_IDupper);
CatIDLOW = Convert.ToInt32("Label2.Text");
CatIDHIGH = Convert.ToInt32("Label3.Text");
}
GridView1.DataBind();
}

|||

I am not sure but I think this may have something to do with the object type coming out of the radiobuttonlist control. don't know where to go from where I am.

thank you,

No comments:

Post a Comment