Click here to Skip to main content
15,118,573 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Suppose you have three columns of table names, fn, ln, code there. Is there a way that column fn in the fourth field put a lable?
The table is in sql
Zoltán Zörgő 23-Aug-12 3:25am
Sorry, what?
Please elaborate your question!
Prabhakaran Soundarapandian 23-Aug-12 3:25am
Can you improve your question?
me64 23-Aug-12 3:30am
I have a table in sql server
Now, i want displaying a field of columns in a label
[no name] 23-Aug-12 3:35am
give you code first!
me64 23-Aug-12 3:38am
I do not
I want to help you
pramod.hegde 23-Aug-12 4:32am
Be clear what you want to say. Elaborate your problem.
me64 23-Aug-12 4:36am
How value of a field into a column, put a label (display in label) ?
me64 23-Aug-12 5:04am
For example, fn column contains the following fields (a table in sql server)
How third field put in a lable?
pradiprenushe 23-Aug-12 6:38am
you want morgan in column right?
me64 23-Aug-12 7:11am
i want display third field in lable.By language C#
pradiprenushe 23-Aug-12 7:13am
Are you using dataset or datareader while getting data from sql?
me64 23-Aug-12 7:16am
i using dataset

There is an type like Object type , your question is not clear..
me64 23-Aug-12 6:33am
This is not Solution, This is comment
me64 23-Aug-12 6:42am
here All contents of the fn column display in the lable
While one must show,For example, to display the third field. Is that Morgan
jeyamothi 23-Aug-12 7:00am
i am not getting you properly
me64 23-Aug-12 7:03am
For example, fn column contains the following fields (a table in sql server)
How third field put in a lable?
But,by c# Language in ASP.NET
jeyamothi 23-Aug-12 7:09am
can you send your code where label filled.
me64 23-Aug-12 7:18am
i do not have
jeyamothi 23-Aug-12 7:37am
then how you check?
ok if your using dataset means use like this

Go through this link

Search for pivot table on google.

If you are using datset then
lblTest.Text= ds.Tables[0].Rows[3]["fn"].ToString();

If using datatable
lblTest.Text = table.Rows[3]["fn"].ToString();

If using datareader

DataReader  dr = cmd.ExecuteReader();
int temp =0;
                    temp = temp+1;
            if(temp ==3)
            lblTest.Text = dr["fn"].Tostring();
me64 23-Aug-12 6:51am
solution must be Language C #.
pradiprenushe 23-Aug-12 7:08am
Do u tou want solution for DataTable from C#? Or you want retrieve fourth row value from table.
me64 23-Aug-12 7:19am
I want retrieve fourth row value from table.
pradiprenushe 23-Aug-12 7:23am
Please see my updated solution
me64 23-Aug-12 8:12am
what problem in line (Label1 = ds.Tables[0].Rows[3]["fn"];)?

SqlConnection con = new SqlConnection();
string str = "Data Source=localhost; initial Catalog=my-db; Integrated Security=True";
con.ConnectionString = str;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = @"select * from mytb";
da.SelectCommand = cmd;
Label1 = ds.Tables[0].Rows[3]["fn"];

Erore message:
Cannot implicitly convert type 'object' to 'System.Web.UI.WebControls.Label'. An explicit conversion exists (are you missing a cast?)
pradiprenushe 23-Aug-12 8:20am
Label1 = ds.Tables[0].Rows[3]["fn"];
here Label.Text you are trying to assign label which is not property.
ds.Tables[0].Rows[3]["fn"] you need to convert to string because text property requires input as string

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900