Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Get Dataset Column Value

Posted on 2012-04-04
5
Medium Priority
?
889 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 500 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 500 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 500 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 500 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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…
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!
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline

971 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