Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
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
Posted
Comments
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

There is an type like Object type , your question is not clear..
 
Share this answer
 
Comments
me64 23-Aug-12 6:33am    
This is not Solution, This is comment
 
Share this answer
 
Comments
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)
Jenifer
Philip
Morgan
Henri
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
Go through this link
http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/

Search for pivot table on google.

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


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


If using datareader

C#
DataReader  dr = cmd.ExecuteReader();
int temp =0;
                while(rdr.Read())
                {
                    temp = temp+1;
            if(temp ==3)
            {
            lblTest.Text = dr["fn"].Tostring();
            }
                }
 
Share this answer
 
v5
Comments
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;
da.Fill(ds);
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?)

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