Search code examples
c#.net-2.0oledb

How to get data from dataset without linq?


Is there a possibility to get data from dataset without using LINQ? I use VS 2005 and .net 2.0.

            string connectionString = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", _DbFile);

            using (OleDbConnection con = new OleDbConnection(connectionString))
            {
                try
                {
                    con.Open();

                    _Data = new DataSet();

                    OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM a", con);
                    adapter.Fill(_Data, "a");

                    adapter = new OleDbDataAdapter("SELECT * FROM b", con);
                    adapter.Fill(_Data, "b");

                    // get data...
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

Solution

  • You can use row and column indexes to reach the cell value. You can also use column names instead of index. 

     if(_Data.Tables.Count > 0 && _Data.Rows.Count > 0 && _Data.Columns.Count > 0)
     {
            string row0col0Data = _Data.Tables[0].Rows[0].Cols[0].ToString();
     }