Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Hi Everyone

I have used a drop down and a label. I want on the selection of the drop down data should be viewed on label.

<code>ex: if user select value from drop down (Apple) so on label it should print (50 per KG)</code>


i have written the code for this query but i am not getting proper answer please check the code and let me know where is the error please

MSIL
private void cmddiscount_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlConnection cnn1 = new SqlConnection(@"Server=NGENIOUS-WSSDEV\SQLEXPRESS;Database=MIC;Trusted_Connection= True");
            cnn1.Open();
            DataSet da = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter("select flat,percentile from discount where flat='Per Unit' and percentile='On MRP' ", cnn1);
            sda.Fill(da, "discount");
            //  for (i = 0; i < da.Tables["discount"].Columns.Count; i++)
            int i = 0;
            for (i = 0; i <= da.Tables["discount"].Columns.Count - 1; i++)
            {
                string x = da.Tables[0].Rows[0][i].ToString();
                if (cmddiscount.SelectedItem.ToString() == "percentile")
                {
                    //if (cmddiscount.SelectedItem.ToString() == x)
                    //{
                    label5.Text = x;
                    //}
                }
                else
                {
                    if (cmddiscount.SelectedItem.ToString() == "flat")
                    {
                        //if (cmddiscount.SelectedItem.ToString() == x)
                        //{
                        label5.Text = x;
                        //}
                    }
                }


<br />
i am getting one same name display on the selection of any from combo box






Data should come from sqldata and I can't use join because there is no relationship between the two tables. Is there any other suggestion on how I can do this ?

2) i am using data grid view in that i want that user should typed manually address and then click on submit then data should save in sql server

the code i have written is giving me error
SqlConnection con = new SqlConnection(@"Server=NGENIOUS-WSSDEV\SQLEXPRESS;Database=MIC;Trusted_Connection= True");
          con.Open();
          SqlCommand cmd = new SqlCommand("insert into clientwiseproductwise(productcategory,discounttype,scount,Dfactor)values ('" + productcategoryDataGridViewTextBoxColumn + "','" + discounttypeDataGridViewTextBoxColumn + "','" + DiscountValue + "','" + dfactorDataGridViewTextBoxColumn + "')", con);


           cmd.ExecuteNonQuery();
           con.Close();





           MessageBox.Show("Data Successfully Submitted");



if in insert statement i put @productcategory then it is telling me must declare variable

if i remove @
then the error is

MSIL
String or binary data would be truncated.
The statement has been terminated.







please help me As soon as possible please
Posted
Updated 15-Nov-10 2:32am
v6
Comments
Vigneshb6 15-Nov-10 4:06am    
Your Question is not clear.

Hi,
Pls change your Query like this.

con.Open();
string sqlStr ="insert into clientwiseproductwise(productcategory,discounttype,scount,Dfactor)values ('" + productcategoryDataGridViewTextBoxColumn + "','" + discounttypeDataGridViewTextBoxColumn + "','" + DiscountValue + "','" + dfactorDataGridViewTextBoxColumn + "')"

SqlCommand cmd = new SqlCommand(sqlStr , con);


Now check the values of sqlStr ..

And run that values into Sqlserver...



Regards,
Saran
 
Share this answer
 
Comments
aayu 15-Nov-10 6:10am    
and what about first question?
Hi,
just user SelectedIndexChanged event

C#
private void myCombo_SelectedIndexChanged(object sender, EventArgs e)
{
     myLabel.Text = myCombo.SelectedItem.ToString();
}


Regards
Robert
 
Share this answer
 
Comments
aayu 15-Nov-10 8:18am    
nope this not the one which i want...........
i want when user select from drop down on label data should view from sql server
Hi Aarti2010,
I did not get your question..
Pls explain about your problem.


Regards,
saran.t
 
Share this answer
 
Comments
Rajesh Anuhya 15-Nov-10 4:34am    
Where is Your Answer..???

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