[英]Retrieving data into textbox from database
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,就像我在其中一條評論中所說的那樣,確保在 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>
您必須在數據表中獲取查詢輸出,然后從那里將該 DataTable 值轉換為字符串。 檢查您是否有權訪問您的標簽。
Label.Text = // 從 DataTable 轉換的字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.