protected void DropDownServerName_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Database_Shared_NotebookConnectionString"].ConnectionString);
conn.Open();
string serverName = DropDownServerName.SelectedValue;
string sqlquery = ("SELECT Architecture FROM tblServer WHERE (ServerName = " + serverName + ")");
SqlCommand command = new SqlCommand(sqlquery, conn);
txtUpdateArchitecture.Text = command.ExecuteScalar().ToString();
conn.Close();
}
DropDownServerName 区域使用 SqlDataSource 连接到 SQL Server 以显示 ServerName 列上的值列表。
在我获得名为“Brad”的选择值之后,我希望 Brad 的 Architecture 列中的值显示在文本框中。但是我得到错误说,无效的列名“Brad”。该列假定为 ServerName,而 Brad 只是 ServerName 列中的一个值。