Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void btnSearch_Click(object sender, EventArgs e)
        {


            if (searchtext.Text == "")
            {
                MessageBox.Show("Plese Inter Employee's ID you are searching for");
                searchtext.Focus();
            }
            else
            {
                
                OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Employees.mdb");
                OleDbDataAdapter ad = new OleDbDataAdapter("select * from Employee where EmpID=@EmpID", con);
                ad.SelectCommand.Parameters.Add("@EmpID", OleDbType.Integer);
                ad.SelectCommand.Parameters["@EmpID"].Value = int.Parse(searchtext.Text);


                DataSet ds = new DataSet();
                ad.Fill(ds, "Emp");
                DGV1.DataSource = ds.Tables["Emp"];

               
                if (ds == null)
                {
                    
                    MessageBox.Show("not found!!");

                }
                else
                {
                   MessageBox.Show("The Employee you are searching for is listed down, if you want to update the data click the arrow sign on the lift side of the record");
                }
            }
Posted
Comments
MeftahDAKHEEL 29-Mar-15 12:35pm    
i need to check my code and update my mistaks please
ilakowalska 29-Mar-15 13:20pm    
This is ok! Good code

Try

C#
if(ds.Tables["Emp"].Rows.Count>0)
{
   MessageBox.Show("Found !!");
}
else
{
   MessageBox.Show("not found!!");
}
 
Share this answer
 
Comments
MeftahDAKHEEL 29-Mar-15 16:55pm    
@Arkadeep, it is good, thanks a lot
Arkadeep De 30-Mar-15 3:06am    
u welcome
Try something like
If(ds.Tables[0].HasRows)
Message employee found
 
Share this answer
 
Comments
MeftahDAKHEEL 29-Mar-15 16:58pm    
thanks its corrict

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900