Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

use where condition and fetch the data
SQL
select * from yourtable where yourcolumn = 'columnVal'
 
Share this answer
 
Comments
[no name] 2-Jul-14 8:23am    
actually 5 values are present against one primary key and i want to bound all that 5 values in combobox against that primary key. here is my 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.Text = dt1.Rows[0]["Lot_No"].ToString();
txtQty.Focus();
Use the query :
Select * from Table_name WHERE Column_Name = Your_Value

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();
 
Share this 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