如何从数据库中获取单个值 [英] How to Get single Value from database

查看:139
本文介绍了如何从数据库中获取单个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...



我只想从数据库中获取一个值,我怎么能检索到它?



我有一个组合框,即组合框显示成员=项目名称,当我从组合框中选择项目名称意味着特定项目ID显示在一个文本框中时,下面的代码将使用值成员在组合框中添加数据。 ..

这里itemselect =我的组合框。



 itemselect.DataSource = sp.datafill( 选择pu.item_id作为puid,it.name作为item_来自sales_items pu,其中的项目为pu.item_id = it.id ); 
itemselect.DisplayMember = Itemname;
itemselect.ValueMember = id;
itemselect.SelectedIndex = -1;





现在如何显示项目在文本框中?

请发送您的想法......

解决方案

我不确定您的意思,但如果您只想获取SelectedItem的SelectedValue,请尝试使用ComboBox的SelectedIndexChange事件。这样的事情...



<前一个=c#> 私人 void itemselect_SelectedIndexChanged( object sender,EventArgs e)
{
textBox1.Text = .Empty;
if (itemselect.SelectedIndex > -1)
{
textBox1.Text = itemselect.SelectedValue.ToString();
}
}


Hi All...

I want only one value from database,How i can i retrieve that??

I have one combobox,that combobox display member=item name, when i select the item name from combobox means tha particular item id show in one textbox,the below code is add the datasoure in combobox with value member...
here itemselect=My combobox.

itemselect.DataSource = sp.datafill("select pu.item_id as puid,it.name as itemname from sales_items pu,items it where pu.item_id=it.id");
           itemselect.DisplayMember = "Itemname";
           itemselect.ValueMember = "id";
           itemselect.SelectedIndex = -1;



now how to show the item is in textbox?
pls send your ideas...

解决方案

I'm not exactly sure what you mean but if you just want to get the SelectedValue for the SelectedItem try using the ComboBox's SelectedIndexChange event. Something like this...

private void itemselect_SelectedIndexChanged(object sender, EventArgs e)
{
    textBox1.Text = string.Empty;
    if (itemselect.SelectedIndex > -1)
    {
        textBox1.Text = itemselect.SelectedValue.ToString();
    }
}


这篇关于如何从数据库中获取单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆