简体   繁体   English

如何检索SQL Server 2005表的列值并将其存储在label.C#ASP.Net中的文本

[英]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". 假设我在“配置文件”表中有一列“ fname”,其值为“ Nikhil”。

How to retrieve column value of sql server table and store it in label.Text of c# ASP.Net. 如何检索SQL Server表的列值并将其存储在C#ASP.Net的label.Text中。

I mean what should be the code if I want label text to be "fname" value that is "Nikhil" 我的意思是,如果我希望标签文本为“ Nikhil”的“ fname”值,应该是什么代码

Connection is already done properly because I am able to display table data in Gridview but not able to display it in label. 连接已经正确完成,因为我可以在Gridview中显示表数据,但不能在标签中显示表数据。

I had also seached but not understood the answer 我也一直在寻找,但不知道答案

label1.Text = ?; label1.Text =?; // I want fname here //我想在这里使用fname

Regards, 问候,

Nikhil 尼基尔

If you have a data in a table dtData then you can use this code. 如果表dtData中有数据,则可以使用此代码。 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 并从网格视图使用此代码Label1.Text = GridView1.Rows[0].Cells[0].Text单元格是网格视图中的列

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检索SQL Server表的列值并将其存储在label.C#ASP.Net中的文本 - How to retrieve column value of sql server table and store it in label.Text of c# ASP.Net linq到实体检索数据库表行值并显示为label.Text C#.net - linq to entities retrieve database table row value and display as label.Text C# .net 如何在ASP.net C#中将HTML文本编辑器内容存储和检索到SQL Server DB - how to store and retrieve the HTML text Editor contents to SQL Server DB in ASP.net C# 如何将通用处理程序绑定到ASP.NET中的Label.Text - How to bind generic handler to Label.Text in ASP.NET 将数据存储在sql server 2005 asp.net c#网站中 - store data in sql server 2005 asp.net c# website Sql 服务器 2005 - Asp.net c# 超时 - Sql Server 2005 - Time Out in Asp.net c# 如何通过C#ASP.net从SQL Server中的文本框存储日期 - How to store date from text box in SQL Server through C# ASP.net 使用 C# 检查 ASP.NET 中 SQL Server 表中的列值是否为空 - Check if column value in SQL Server table is null in ASP.NET using C# 如何使用sql server 2005在asp.net c#中在webite中显示长内容 - How to display a long content in the webite in asp.net c# using sql server 2005 获取ASP.net C#中Gridview中的列的值/文本以显示在标签中 - Get the value/text of a column in a Gridview in ASP.net C# to display in a label
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM