hi, i'm new to c# programming and i have this problem that i encountered while trying to create a database browser. Here is my code:

private void button1_Click(object sender, EventArgs e)
        {
            string search;
            search = searchbox.Text;
            if (search == "")
            {
                MessageBox.Show("You have not entered anything. Please enter the error code to display the correct error description.");
            }
            switch(search.Remove(4))
            {
                case "AH01":
                    {
                    OleDbConnection conn = new OleDbConnection(@"provider = Microsoft.Jet.OLEDB.4.0;Data Source= C:\Documents and Settings\Administrator\My Documents\Error Status list Database.mdb");
                    OleDbCommand ah = new OleDbCommand("SELECT ID, Status FROM AH01", conn);
                    progress.Value = 40;
                    conn.Open();
                    OleDbDataReader dr = ah.ExecuteReader();
                    while (dr.Read())
                        {
                        GridView1.DataSource = dr;
                        }
                    dr.Close();
                    progress.Value = 100;
                    conn.Close();
                    break;

                    }

my problem is that when i debugged it, there was no error but the data that is searched does not display in the datagrid i have created. really need your feed back on this. thanks

I'm guessing you have to update it, I don't have much experience with DataGrid views, but have you tried the doing:

GridView1.Show();

Or maybe:

GridView1.Update();

I might be wrong, maybe someone with more experience can suggest something else.

You cannot set DataReader as a binding source to any control. Instead, you should use DataAdapter class.

//...
progress.Value = 40;
OleDbConnection conn = new OleDbConnection("connString");
DataTable table = new DataTable(); //can be a class variable too.
OleDbDataAdapter da = new OleDbDataAdapter("SELECT ID, Status FROM AH01", conn);
da.Fill(table);
GridView1.DataSource = table.DefaultView;
conn.Dispose();
progress.Value = 100;

i tried the code that you have given Mitja. and it did display. thanks for that. the only thing bothering me now is how can I exclusively display the certain item that is searched and also, is the default for the table only two columns?coz i tried adding fields to be searched and it displayed an error "No value given for one or more required parameters."? I tried 3 fields and it worked but when i added 1 more, the error was displayed again.thanks for your insights on this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.