Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i made two dropdowns and 1 lable.

1.ddCategory dropdown
2.ddProduct dropdown
3.Price lable

i hvae 3 tables in database. 1st is CategoryData 2nd is ProductData and 3rd is is PriceData

CAtegoryData is databound to ddCategory // (Id,CAtegory_Id,Name)4 categories
ProductData is databound to ddProduct // ((Id,Category_Id,Product_Name)8 Product in each category
Pricedata has price. (Id,Category_Id,Price)

user select category. product are shown of the selected category. and then the price should be displayed on the lable.

i just couldn't display price into the lable.

i guess my select statement is wrong.

code here, please help asap


SqlCommand cmd = new SqlCommand("Select * From PriceData Where Id ='" + ddCategory.SelectedValue + "'", con);

       cmd.Parameters.AddWithValue("@Price", ddProduct.SelectedItem.Value);
       cmd.CommandType = CommandType.Text;

       cmd.Connection = con;
       SqlDataReader sdr = cmd.ExecuteReader();

       if (sdr.Read())
       {

           Price.Text = sdr["Price"].ToString();
       }
Posted
Updated 26-Dec-14 6:56am
v2
Comments
ZurdoDev 26-Dec-14 13:39pm    
Debug it and find out what is happening.

1 solution

This should resolve your problem.

C#
SqlCommand cmd = new SqlCommand("Select * From PriceData Where Id =" + ddProduct.SelectedValue.ToString(), con);
        cmd.CommandType = CommandType.Text; 
        cmd.Connection = con;
        string price = cmd.ExecuteScalar();
        
        if (!price.Equals(String.Empty))
        { 
            Price.Text = price;
        }   


Assumption:
PriceData table is storing productid in the field Id


In case this doesn't resolve the issue, please let me know !
 
Share this answer
 
v2

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



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