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 列の単なる値です。