我有一個下拉列表我想在後面的代碼中使用一個SQL中的ID,但我得到錯誤...'selCurrentManuf'未被聲明。它可能是無法訪問,由於其保護水平
未聲明。由於其保護級別,它可能無法訪問。
<asp:DropDownList
selectedvalue='<%#Container.DataItem("manufidcurrent")%>'
ID="selCurrentManuf"
Runat="Server"
DataTextField="Desc"
DataValueField="manufid"
DataSource="<%# GetCurrentManuf() %>"
autopostback="true"
OnSelectedIndexChanged="selCurrentManuf_SelectedIndexChanged" ></asp:DropDownList>
在後面的代碼我有一個功能,試圖用所選擇的選項...
Function GetCurrentModel() As DataSet
Dim mySession = System.Web.HttpContext.Current.Session
Dim myQuery As String = "SELECT * FROM model where id = " + selCurrentManuf.SelectedItem.Value
Dim myConnection As New MySqlConnection(mySession("localConn"))
myConnection.Open()
Dim myCommand As New MySqlCommand(myQuery, myConnection)
Dim myDataAdapter = New MySqlDataAdapter(myCommand)
Dim myDataset As New DataSet
myDataAdapter.Fill(myDataset, "model")
Dim dr As DataRow = myDataset.Tables(0).NewRow
myDataset.Tables(0).Rows.Add(dr)
GetCurrentModel = myDataset
End Function
*** ***沒有聲明什麼...? –
這對於SQL注入已經成熟,您應該考慮使用參數化查詢。 – CAbbott
[dropdownlist未被聲明可能重複。它可能無法訪問,由於其保護級別](http://stackoverflow.com/questions/7678387/dropdownlist-is-not-declared-it-may-be-inaccessible-due-to-its-protection-level) –