sanlorenzo
asked on
Visual Studio 2008 Multiselection querry with LINQ Query
With Visual Studio 2008 and SQL Server 2005 I have a Form where i drag the data Class (tbl_Name ) Linked to a Table Named tbl_Name
The Table has 5 Column : NameID/Name/Town/Country/C ontinent
So the Form show a Grid representing the tbl_Name with the 5 column
I have in same form Toolstrip 2 combo box named as follow :
ToolStripComboBox1 It Populate Taking Data from the column Continent
ToolStripComboBox2 It Populate Taking Data from the collumn Country
In the Form I have also a Button : Button3 that i use to trigger the filter action
I am using the following code to filter the Grid by Continent and by Country and it works very well
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim MultyQuerry = From tbl_Name In db.tbl_Names _
Where tbl_Name.Continent = Me.ToolStripComboBox1.Sele ctedItem.T oString _
And tbl_Name.Country = Me.ToolStripComboBox2.Sele ctedItem.T oString _
Select tbl_Name
Me.Tbl_NameBindingSource.D ataSource = MultyQuerry
End Sub
Now let me come to my Problem
All is working if i have both Combo Box with a value :
But it give me error if one of the comboBox is empty
Is anyone helping me to change my code so to handle the Null value ???
Thanks
The Table has 5 Column : NameID/Name/Town/Country/C
So the Form show a Grid representing the tbl_Name with the 5 column
I have in same form Toolstrip 2 combo box named as follow :
ToolStripComboBox1 It Populate Taking Data from the column Continent
ToolStripComboBox2 It Populate Taking Data from the collumn Country
In the Form I have also a Button : Button3 that i use to trigger the filter action
I am using the following code to filter the Grid by Continent and by Country and it works very well
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim MultyQuerry = From tbl_Name In db.tbl_Names _
Where tbl_Name.Continent = Me.ToolStripComboBox1.Sele
And tbl_Name.Country = Me.ToolStripComboBox2.Sele
Select tbl_Name
Me.Tbl_NameBindingSource.D
End Sub
Now let me come to my Problem
All is working if i have both Combo Box with a value :
But it give me error if one of the comboBox is empty
Is anyone helping me to change my code so to handle the Null value ???
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there any one to help , if for instance the Combo Box instead being 2 become 4 , i see i should have a better code to apply ???
Thanks
Thanks
ASKER
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Me.ToolStripComboBox1.Sele
Dim MultyQuerry = From tbl_Name In db.tbl_Names _
Where tbl_Name.Continent = Me.ToolStripComboBox1.Sele
And tbl_Name.Country = Me.ToolStripComboBox2.Sele
Select tbl_Name
Me.Tbl_NameBindingSource.D
End If
If Me.ToolStripComboBox1.Sele
Dim MultyQuerry1 = From tbl_Name In db.tbl_Names _
Where tbl_Name.Continent = Me.ToolStripComboBox1.Sele
Select tbl_Name
Me.Tbl_NameBindingSource.D
End If
If Me.ToolStripComboBox1.Sele
Dim MultyQuerry2 = From tbl_Name In db.tbl_Names _
Where tbl_Name.Country = Me.ToolStripComboBox2.Sele
Select tbl_Name
Me.Tbl_NameBindingSource.D
End If
If Me.ToolStripComboBox1.Sele
Dim MultyQuerry3 = From tbl_Name In db.tbl_Names
Select Case db.tbl_Names
End Select
Me.Tbl_NameBindingSource.D
End If
End Sub