Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello friends,
I am making report and I have one issue such that when we selecting employee from combobox and run the report then it must show particular employee.
And when I select nothing and run report then all employee from database must be display on report.so what kind of query I should write.
Posted 29-Dec-12 23:52pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you havent mentioned any code so we have fair idea of your data's. but with that knowledge a sample query may be help you to get going.
 
you need to write a select query with where condition to filter out the matching employee name. if filter is empty select all.
eg:
select * from employeeTable; // this query will return all the rows inside the table employeeTable
 
select * from employeeTable where EmployeeName = txtFromCombo; // this will return row that matching the EmployeeName equals to the value txtFromCombo where txtFromCombo is a string.
  Permalink  
Comments
Tejas11C at 30-Dec-12 5:54am
   
no i want two query to be executed at a time(when i select employee it filters that particular employee but if i don't select any employee then it automatically generates reports of all employees means like a if else statements) and i want to write this query in table adapter in visual studio
jibesh at 30-Dec-12 6:00am
   
are you using any stored procedure?
jibesh at 30-Dec-12 6:45am
   
you can use the If else statement in your stored procedure if your using a SP otherwise you need to build a two queries. I dont think that you can have single query with and without where condition.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

//you can get the combo value in this way
 
if (combo.Text  != "Please Select" && combo.Text  != "All"){
MessageBox.Show("Employee Id is "+ cboItemName.SelectedValue.ToString());
}
else
{
MessageBox.Show("No Employee Select");
}
</pre>
 
May this help you
  Permalink  
Comments
jibesh at 30-Dec-12 5:43am
   
This is not the right solution for the OPs question. OP is asking about how to prepare the query and not to select the combo.
Ronjon1 at 30-Dec-12 6:00am
   
what do you mean i just tell him, how can he get the id from combo box ....
jibesh at 30-Dec-12 6:03am
   
Yes. but thats not what he is asking for. read his question.
'problem related to query' and '... what kind of query i should write'
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

for particular Employee you write where condition in if clause and when you want to all employee information you code normal select query in else clause.............
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100