Click here to Skip to main content
15,868,037 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Anyone know this......

this is the coding for price ranges........but while executing it produce error like" input string is not in correct format".......



C#
protected void BulletedList3_Click(object sender, BulletedListEventArgs e)
    {
       
       string price = BulletedList3.Items[e.Index].Value;
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        if (Convert.ToInt32( price )< 500)
        {
            SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price='" + price + "' and status='A' and type='retail'", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataList1.DataSource = ds;
            DataList1.DataBind();
            con.Close();
        }
    }
Posted
Updated 20-Nov-11 21:38pm
v2
Comments
demouser743 21-Nov-11 4:13am    
What you declared your price in SQL. Is it in an int or varchar

Use a parametrized query instead - and feed it the converted price you did earlier. You are doing the conversion anyway, so why not use the value properly?
SQL
int i = Convert.ToInt32( price );
if (i < 500)
{
SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price=@PR and status='A' and type='retail'", con);
cmp.Parameters.AddWithValue("@PR", i);
 
Share this answer
 
Comments
sathiyak 21-Nov-11 3:42am    
sorry again it shows the same error...in the first line...
OriginalGriff 21-Nov-11 4:49am    
Then the problem is that your price string is not an integer!

Have a look at it (in the debugger) and see what it is...
Check once what data type you have given for Price in database
and in code. If they are not same you need to convert the data type of code side variable
 
Share this answer
 
hey buddy... see if you give your input in correct way, then u wont get this error... for example if you going to buy something, u will enter prize range starts from 2000 to 4000 ... as like you have to give correct input strings manually
 
Share this answer
 
Hi,

change the SQLcommand code

C#
SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price=" + price + " and status='A' and type='retail'", con);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900