Solved

C# Get Dataset Column Value

Posted on 2012-04-04
5
827 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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