Solved

C# Get Dataset Column Value

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

17 Experts available now in Live!

Get 1:1 Help Now