C# Get Dataset Column Value

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;
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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!
Kiran SonawaneProject LeadCommented:
You can do this like


But instead of dataset you can think like this


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

käµfm³d 👽Commented:
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

pauledwardianAuthor Commented:
Thank you all!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.