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

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.............
 
Share this answer
 
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:
SQL
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.
 
Share this answer
 
Comments
Tejas11C 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 30-Dec-12 6:00am    
are you using any stored procedure?
Jibesh 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.
//you can get the combo value in this way

SQL
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
 
Share this answer
 
Comments
Jibesh 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 30-Dec-12 6:00am    
what do you mean i just tell him, how can he get the id from combo box ....
Jibesh 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'

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