C# Get Dataset Column Value

Posted on 2012-04-04
Last Modified: 2012-04-06
Can someone please help me to figure out the value of the dataset column in C# ASP.Net.
I need to assign SPECIFIC column number values to SPECIFIC textboxes.
This is how I did it but it doesnt let me to use Table.
I created a Dataset in Visual Studio and called it MyDataset.

  string connString = ConfigurationManager.ConnectionStrings["App"].ToString();
                SqlConnection conn = new SqlConnection(connString);
            MyDataset ds = new MyDataset();
           this.SN.Text=  ds.Tables[0].Columns;
Question by:pauledwardian
LVL 21

Assisted Solution

masterpass earned 125 total points
ID: 37809447

this.SN.Tex = ds.Tables[0].Columns[0].ToString(); 
TextBox2.Text = ds.Tables[0].Columns[1].ToString(); 
TextBox2.Text = ds.Tables[0].Columns[2].ToString(); 

Open in new window

hope this helps!
LVL 17

Accepted Solution

sonawanekiran earned 125 total points
ID: 37809450
You can do this like


But instead of dataset you can think like this

Assisted Solution

sachinpatil10d earned 125 total points
ID: 37809457
Use any one of it

this.SN.Text=  Convert.ToString(ds.Tables[0].Columns[0]);

Open in new window


this.SN.Text=  Convert.ToString(ds.Tables["datatableName"].Columns["ColumnName"]);

Open in new window

LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 125 total points
ID: 37809461
But you haven't filled the DataSet with anything!!!

The DataSet class has a method named Load which is overloaded. One of the overloads accepts a DataReader as a parameter. Try modding your code to this:

string connString = ConfigurationManager.ConnectionStrings["App"].ToString();
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("SELECT ssn, fName, lName FROM tblName WHERE key = @key", conn);

cmd.Parameters.AddWithValue("@key", someKeyValue);
MyDataset ds = new MyDataset();
SqlDataReader reader = cmd.ExecuteReader();


 this.SN.Text=  ds.Tables[0].Columns[0] as string;

Open in new window


Author Closing Comment

ID: 37817342
Thank you all!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now