Link to home
Start Free TrialLog in
Avatar of praveenuni
praveenuni

asked on

Read values from DataSet

Hello,

I'm getting the dataset from another asp.net into my current page. I want to read the total number of tables (into string), table names (into arraylist). and How can read any value from any table in the dataset. For eg., if I want to read 2nd value in 2nd column in 3rd table of dataset, how can I do that?

Thanks
Praveen
Avatar of rafrancisco
rafrancisco

Total Number of Tables : dataSet.Tables.Count.ToString()

Table Names Into ArrayList:

string[] tableNames = new string[dataSet.Tables.Count];                  
for (int i = 0; i < dataSet.Tables.Count; i++)
           tableNames[i] = dataSet.Tables[i].TableName;

To read any Value in Table in DataSet

dataSet.Tables[2].Rows[1][1].ToString();
Avatar of praveenuni

ASKER

what does Tables[2].Rows[2][3] means? Is it the second value in 3rd column in table 2?

Thanks
Praveen
Indexes in C# start with 0.  So this means the 3rd row value of the 4th column in the 3rd table.
I tried this Tables[0].Rows[0][0]   - to get the 1st row value of 1st column in 1st table. But the system is throwing an error saying " There is no row at position1".
But in my database I have 3 tables each with 2 records and 2 columns. Whys is that happening?

Thanks
Praveen
How did you load the database tables into your dataset?  Are you sure it was properly loaded?
This is my first time loading the database tables into dataset. I created the dataset following the walk through in one of the websites. This is how I did it
(Created ODBC Connection ... dragged and dropped the tables into the form (it created 3 data adapters for 3 tables) .. selected one data adapter and created dataset with all the tables ) .. Is there anything wrong I did ?
I tried to enter values into the dataset manually like this :

            this.GBResults.Tables.Add("Table1");
            this.GBResults.Tables["Table1"].Columns.Add("Field");
            this.GBResults.Tables["Table1"].Columns.Add("ID");

            this.GBResults.Tables["Table1"].Rows[0][0] = 1;
            this.GBResults.Tables["Table1"].Rows[0][1] = 2;
            this.GBResults.Tables["Table1"].Rows[1][0] = 3;
            this.GBResults.Tables["Table1"].Rows[1][1] = 4;

But the system is throwing the same "There is row at position 0" error.
Why is this happening?

Thanks
Praveen
ASKER CERTIFIED SOLUTION
Avatar of rafrancisco
rafrancisco

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial