如何针对组合框中的一个列值获取所有行。 [英] How to fetch all rows against one column value in combobox.

查看:46
本文介绍了如何针对组合框中的一个列值获取所有行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库表中获取一个列值的数据。我想根据该值获取所有行。例如,如果值8在列中存在两次,则查询应该根据值8获取所有行。

i am fetching data from database table against one column value. i want to fetch all rows against that value. for example if value 8 exists twice in column then query should fetch all rows against value 8.

推荐答案

使用where where条件并获取数据

use where condition and fetch the data
select * from yourtable where yourcolumn = 'columnVal'


使用查询:
Select * from Table_name WHERE Column_Name = Your_Value



让我们说你的结果数据表有5行而你想要将Column1绑定到您的下拉列表。



您只需要将数值从数据绑定到下拉列表



这里我改变你的代码


Lets say your result datatable has 5 rows and you want to bind Column1 to your dropdown.

All you need to do is just bind your values from datatable to dropdownlist

Here Iam changing your code

DataTable dt1 = new DataTable();
SqlConnection con1 = new SqlConnection(str);
con1.Open();

string query1 = "select Lot_No from tblStockDetail where ItemID = '" + txtItemID.Text + "'";
SqlDataAdapter ad1 = new SqlDataAdapter(query1, con1);
ad1.Fill(dt1);
 
cboLotNo.DataSource = dt1;
cboLotNo.DataTextField = "Column_Name"; // Lot_No Text displayed for User
cboLotNo.DataValueField = "Column_Name"; // Associated Primary key for each item
cboLotNo.DataBind();

txtQty.Focus();


这篇关于如何针对组合框中的一个列值获取所有行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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