Hey there.

How do i search through my Datatable. I know how to do it when there is a Datagridview involved, but i dont have one in this case.

I know they say you should do this

DataRow foundRow = dataSet1.Tables["AnyTable"].Rows.Find(s);

Something like that, but i have no idea what the DAtaset1 is?

this is my code.

DataTable dTable = new DataTable();
            OleDbDataAdapter dAdapter;
            
            
            String connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\Resources\\db1.mdb";
            string query = "SELECT * FROM AutoReminder";

            //create an OleDbDataAdapter to execute the query
            dAdapter = new OleDbDataAdapter(query, connString);

            //create a command builder
            OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
            //fill the DataTable
            dAdapter.Fill(dTable);

So i filled up my datatable, but now how do i search thought it, say for a number bigger that 5 in the "Amount" column in AutoReminder? As i have No Clue what so ever.

Thank you =)

I did a semple code, to see what dataSet and dataTables are all about. To test this method, paste it into a windows application project, and run it.
Put a break point and go through the code line by line (with F11).

private void Method()
        {
            DataSet ds = new DataSet();
            DataTable table1 = new DataTable("table one");
            DataTable table2 = new DataTable("table two");

            //creating columns for the tables:
            table1.Columns.Add(new DataColumn("id", typeof(int)));
            table1.Columns.Add(new DataColumn("someText", typeof(string)));

            table2.Columns.Add(new DataColumn("id2", typeof(int)));
            table2.Columns.Add(new DataColumn("someOtherText", typeof(string)));

            //populating tables, one by one and add them to dataSet:
            //populating table 1:
            DataRow dr;
            for (int i = 1; i < 13; i++)
            {
                dr = table1.NewRow();
                dr["id"] = i;
                dr["someText"] = "text with number " + i.ToString();
                table1.Rows.Add(dr);
            }

            //populating table 2:
            for (int i = 101; i < 113; i++)
            {
                dr = table2.NewRow();
                dr["id2"] = i;
                dr["someOtherText"] = "other text with number " + i.ToString();
                table2.Rows.Add(dr);
            }

            //adding both tables to dataSet:
            ds.Tables.AddRange(new DataTable[] { table1, table2 });
            //you could add them seperately, like:
            //ds.Tables.Add(table1);
            //ds.Tables.Add(table2);

            //Now lets loop through the dataSet and write the results out (int messageBox):
            for (int i = 0; i < ds.Tables.Count; i++)      //LOOP THROUGH TABLES OF DATASET
            {
                string text = null;
                foreach (DataRow dr1 in ds.Tables[i].Rows) //LOOP TRGOUGH THE ROWS OF DATATABLE
                {
                    string a = dr1[0].ToString();
                    string b = dr1[1].ToString();
                    text += a + ". " + b + Environment.NewLine;
                }
                MessageBox.Show("In dataSet is dataTable of index [" + i + "] with values:\n" + text);
            }
        }

Edited 5 Years Ago by Mitja Bonca: n/a

Comments
Went further than just telling me how to do it, but showed me the diffirence between the two

I did a semple code, to see what dataSet and dataTables are all about. To test this method, paste it into a windows application project, and run it.
Put a break point and go through the code line by line (with F11).

private void Method()
        {
            DataSet ds = new DataSet();
            DataTable table1 = new DataTable("table one");
            DataTable table2 = new DataTable("table two");

            //creating columns for the tables:
            table1.Columns.Add(new DataColumn("id", typeof(int)));
            table1.Columns.Add(new DataColumn("someText", typeof(string)));

            table2.Columns.Add(new DataColumn("id2", typeof(int)));
            table2.Columns.Add(new DataColumn("someOtherText", typeof(string)));

            //populating tables, one by one and add them to dataSet:
            //populating table 1:
            DataRow dr;
            for (int i = 1; i < 13; i++)
            {
                dr = table1.NewRow();
                dr["id"] = i;
                dr["someText"] = "text with number " + i.ToString();
                table1.Rows.Add(dr);
            }

            //populating table 2:
            for (int i = 101; i < 113; i++)
            {
                dr = table2.NewRow();
                dr["id2"] = i;
                dr["someOtherText"] = "other text with number " + i.ToString();
                table2.Rows.Add(dr);
            }

            //adding both tables to dataSet:
            ds.Tables.AddRange(new DataTable[] { table1, table2 });
            //you could add them seperately, like:
            //ds.Tables.Add(table1);
            //ds.Tables.Add(table2);

            //Now lets loop through the dataSet and write the results out (int messageBox):
            for (int i = 0; i < ds.Tables.Count; i++)      //LOOP THROUGH TABLES OF DATASET
            {
                string text = null;
                foreach (DataRow dr1 in ds.Tables[i].Rows) //LOOP TRGOUGH THE ROWS OF DATATABLE
                {
                    string a = dr1[0].ToString();
                    string b = dr1[1].ToString();
                    text += a + ". " + b + Environment.NewLine;
                }
                MessageBox.Show("In dataSet is dataTable of index [" + i + "] with values:\n" + text);
            }
        }

Ah Great, this helped me allot. I'm Really beginning to understand the concept behind databases, datasets and datatables

Thank you =)

This question has already been answered. Start a new discussion instead.