0
我有一些文本框(使用VS2010)我想填充從SQL Server數據庫中的列的值基於某人從組合框中選擇的項目。起初,我能夠顯示組合框中第一個項目的值,但是當我調試時,現在什麼都沒有顯示。代碼:VB.NET問題從SQL Server的數據加載文本框
Private Sub loadfields(sender As System.Object, e As System.EventArgs) Handles client_selection_combobox.SelectedIndexChanged
Using myconnection As New SqlConnection("connection string")
Dim loadfields As String = "SELECT company FROM ClientFileDatabase WHERE [email protected];"
Dim loadfields_sqlcommand As New SqlCommand(loadfields, myconnection)
loadfields_sqlcommand.Parameters.Add("@company", SqlDbType.NVarChar)
loadfields_sqlcommand.Parameters("@company").Value = client_selection_combobox.SelectedIndex.ToString
Dim loadfields_dataadapter As New SqlDataAdapter
loadfields_dataadapter.SelectCommand = loadfields_sqlcommand
Dim loadfields_dataset As DataSet = New DataSet()
loadfields_dataadapter.Fill(loadfields_dataset, "ClientFileDatabase")
Dim loadfields_dataview = New DataView(loadfields_dataset.Tables("ClientFileDatabase"))
companyname_textbox.DataBindings.Clear()
companyname_textbox.DataBindings.Add("Text", loadfields_dataview, "Company")
taxid_textbox.DataBindings.Clear()
taxid_textbox.DataBindings.Add("Text", loadfields_dataview, "TaxIDNumber")
accountmanager_textbox.DataBindings.Clear()
accountmanager_textbox.DataBindings.Add("Text", loadfields_dataview, "AccountManager")
etc...
End Using
End Sub
我也使用SelectedValueChanged和SelectionChangeCommitted事件處理程序無濟於事嘗試。設置數據綁定後也嘗試使用刷新,沒有幫助。歡迎任何建議,謝謝!
asp.net或windows窗體? –
您不檢索TaxIDNumber和AccountManager的字段數據。這只是一個打字錯誤,或者你真的只是「從......選擇公司」。 – Steve
這是一個打字錯誤,抱歉。這是Windows窗體。 – user1601292