[英]Retrieving data into textbox from database
The text of Label1
doesn't change, what could be the cause of this issue? Label1
的文本没有改变,这个问题的原因可能是什么?
try
{
string connectionString = @"Data Source = (localdb)\MSSQLLocalDB; Initial Catalog = db1; Integrated Security = True";
SqlConnection cnn = new SqlConnection(connectionString);
string query = "SELECT RNO FROM TABLE1 WHERE RNO='" + PRrno.Text + "'";
SqlCommand cd = new SqlCommand(query, cnn);
cnn.Open();
SqlDataReader reader = cd.ExecuteReader();
while (reader.Read())
{
Label1.Text = reader["RNO"].ToString();
}
reader.Close();
cnn.Close();
}
Gaurav Thapa, like I said in one of the comments, make sure in the aspx file your elements have runat="server" also put all the elements you want to get refreshed inside an Ajax Update Panel Gaurav Thapa,就像我在其中一条评论中所说的那样,确保在 aspx 文件中您的元素具有 runat="server" 还将您想要刷新的所有元素放在 Ajax 更新面板中
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>UpdatePanel</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Always">
<ContentTemplate>
<asp:Label runat="server" id="PRrno" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
You have to get query output in data table and then from there convert that DataTable value to string.您必须在数据表中获取查询输出,然后从那里将该 DataTable 值转换为字符串。 Check if you have access to your label.
检查您是否有权访问您的标签。
Label.Text = // String that you converted from DataTable Label.Text = // 从 DataTable 转换的字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.