?
Solved

Read values from DataSet

Posted on 2005-04-20
8
Medium Priority
?
2,232 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:praveenuni
  • 4
  • 4
8 Comments
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13828085
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();
0
 

Author Comment

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

Thanks
Praveen
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13829472
Indexes in C# start with 0.  So this means the 3rd row value of the 4th column in the 3rd table.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:praveenuni
ID: 13829488
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
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13829492
How did you load the database tables into your dataset?  Are you sure it was properly loaded?
0
 

Author Comment

by:praveenuni
ID: 13829511
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 ?
0
 

Author Comment

by:praveenuni
ID: 13829569
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
0
 
LVL 28

Accepted Solution

by:
rafrancisco earned 2000 total points
ID: 13830798
Try this one to access the first column on the first row:

foreach (DataRow dataRow in this.GBResults.Tables["Table1"].Rows) {
     dataRow[0] <-- This is what you need to retrieve the first column of the first row.  See if you will still get the error.
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question