从combox框中选择的项目应在标签上查看 [英] Selected item from combox box should be view on label
问题描述
大家好
我使用了一个下拉菜单和一个标签.我想在下拉列表中选择应该在标签上查看的数据.
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
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
数据应来自sqldata,并且我不能使用join,因为两个表之间没有关系.关于如何执行此操作还有其他建议吗?
2)我正在使用数据网格视图,因为我希望该用户应手动键入地址,然后单击提交,然后数据应保存在sql server中
我编写的代码给了我错误
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");
如果在插入语句中我输入了@productcategory,那么它告诉我必须声明变量
如果我删除@
那么错误是
if in insert statement i put @productcategory then it is telling me must declare variable
if i remove @
then the error is
String or binary data would be truncated.
The statement has been terminated.
请尽快帮助我
please help me As soon as possible please
推荐答案
您好,
请像这样更改您的查询.
con.Open();
字符串sqlStr =插入clientwiseproductwise(productcategory,discounttype,scount,Dfactor)值(""+ productcategoryDataGridViewTextBoxColumn +"''," + DiscounttypeDataGridViewTextBoxColumn +'',""+ DiscountValue +"'','' "+ dfactorDataGridViewTextBoxColumn +")"
SqlCommand cmd =新的SqlCommand(sqlStr,con);
现在检查sqlStr的值..
并将这些值运行到Sqlserver中...
问候,
Saran
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
只是用户SelectedIndexChanged事件
Hi,
just user SelectedIndexChanged event
private void myCombo_SelectedIndexChanged(object sender, EventArgs e)
{
myLabel.Text = myCombo.SelectedItem.ToString();
}
问候
罗伯特
Regards
Robert
嗨Aarti2010,
我没收到你的问题.
请说明您的问题.
问候,
saran.t
Hi Aarti2010,
I did not get your question..
Pls explain about your problem.
Regards,
saran.t
这篇关于从combox框中选择的项目应在标签上查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!