0
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");
                }
            }

Edited by deceptikon: Moved to C# forum

5
Contributors
5
Replies
15
Views
1 Year
Discussion Span
Last Post by deltaitservices
0

Hello Meftah
First of all, I will like to info you that this is not C language, you might have post in wrong section, this belong to C# if I am right....
So, Do you have any Issue with this?

0

Ok in any case apart from the fact that your code is structured badly (we canleave that for now), you are checking if ds is null. It never will be as you are creating it like this:

DataSet ds = new DataSet();

Instead try maybe counting how many rows you have?

Edited by DaveAmour: Typo

0

That code is definitely C#. Since the question did not ask about conversion to C, I've moved the thread to the C# forum so that the resident experts have a better chance of seeing and answering it.

0

Hiii

You just simply modify the condition and its work fine like

if (ds.Table["Emp"].Rows.Count==0)

    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");
}

This condition work fine what you are looking for
Thanks

Edited by pritaeas: Removed fake signature.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.