Solved

C# Get Dataset Column Value

Posted on 2012-04-04
5
836 Views
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);
            conn.Open();
            MyDataset ds = new MyDataset();
           this.SN.Text=  ds.Tables[0].Columns;
0
Comment
Question by:pauledwardian
5 Comments
 
LVL 21

Assisted Solution

by:masterpass
masterpass earned 125 total points
ID: 37809447
Try

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!
0
 
LVL 17

Accepted Solution

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

ds.Tables[0].Rows[0][0].ToString();

But instead of dataset you can think like this

http://stackoverflow.com/questions/4298631/how-to-fill-textbox-from-dataset
0
 
LVL 9

Assisted Solution

by:sachinpatil10d
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


or

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

Open in new window

0
 
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);
conn.Open();
MyDataset ds = new MyDataset();
SqlDataReader reader = cmd.ExecuteReader();
ds.Load(reader);

reader.Dispose();
conn.Dispose();

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

Open in new window

0
 

Author Closing Comment

by:pauledwardian
ID: 37817342
Thank you all!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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