开发者

How to retrieve column value of sql server 2005 table and store it in label.Text of c# ASP.Net

My question is

Suppose I have a Column "fname" whose value is 'Nikhil' in table "profile".

How to retrieve column value of sql server table and store it in label.Text of c# ASP.Net.

I mean what should be the code if I want label text to be "fname" value that is "Nikhil"

Connection is already done properly because I am able to display table data in Gridview but not able to display it in label.

I had also 开发者_如何学编程seached but not understood the answer

label1.Text = ?; // I want fname here

Regards,

Nikhil


Note that Your query needs to be whatever it is to get the proper name

String fname = ""
// Create a new SqlCommand with your query to get the proper name and the connection string
SqlCommand getFnameCommand = New SqlCommand("SELECT TOP 1 fname FROM profile ORDER BY fname DESC;", New SqlClient.SqlConnection"Your Connection String"))
getFnameCommand.Connection.Open() // Open the SqlConnection
fname = getFnameCommand.ExecuteScalar() // This pulls the result from the first column of the first row of your query result
getFnameCommand.Connection.Close() //Close the SqlConnection
label1.text=fname; //Set your label text to the data you just pulled


If you have a data in a table dtData then you can use this code. int rowindex = 0; Label1.Text=dtData.Rows[rowindex]["column name"].ToString();

and from grid view use this code Label1.Text = GridView1.Rows[0].Cells[0].Text Cell is the column in the grid view

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜