Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to filter comboboxes populated with data from a local sqlserverce database. My task is to select one index in one combobox and have that result filter the next combobox. Would LINQ work for this or can I do it with just plain SQL? I am using Visual Studio 2010/2012 with SQL Server CE Edition. I would appreciate any help.
Posted
Comments
Rockstar_ 11-Sep-12 1:06am    
yes you can do it just by plain sql
Rockstar_ 11-Sep-12 1:07am    
Just write your code in the selectedIndex event of the first combobox.
ridoy 11-Sep-12 1:19am    
you can do it in both ways..only sql or only LINQ can do it.

Hi,

ofcourse you can use linq in this.

try this,

C#
protected void combobox1_selectedIndexChanged(object sender, EventArgs e)
{
   //DataSet Objs holds data from sql server with two datatables one is source for combobox1 and other is source for combobox2
   DataTable dt = (from val in Objds.Tables[2].AsEnumerable() where val.Field<string>("Column1")== combobox1.SelectedValue select val).CopyToDataTable();

combobox2.DataTextField="Column2";
combobox2.DataValueField="Column1";
combobox2.DataSource = dt;

}


hope it helps.
 
Share this answer
 
v2
 
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