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已連接到SQL Server使用SqlDataSource顯示ServerName列上的值列表。從sql server獲取數據到文本框錯誤消息
當我得到一個名爲「Brad」的選擇值,並且我希望來自Brad的Architecture列的值顯示在文本框中。但是,我得到錯誤說,無效的列名稱「布拉德」。該列假設爲ServerName,而Brad只是ServerName列中的一個值。
從來沒有像這樣連接,使用參數 –