on FbuildingSettings.vb
- 表格
Public camButtonDtable As DataTable
然后我在Fbuilding.vb
- 表单
Dim names = From row In FbuildingSettings.camButtonDtable.AsEnumerable() Select row.Field(Of String)("Building") Distinct
For Each word In names
ComboBox1.Items.Add(word)
Next
几乎按我的意愿行事,从列中获取每个不同的数据。所以我在FbuildingSettings.vb
Dim names = From row In camButtonDtable.AsEnumerable() Select row.Field(Of String)("Building") Distinct
For Each word In names
comboBuilding.Items.Add(word)
Next
我收到错误:
试过这个:Public camButtonDtable As New DataTable
- 它确实编译了,但是comboBox没有显示任何东西
我做错了什么?
答案 0 :(得分:1)
<强>原因强>
DataTable
,而是在DataTable
被实例化时进行了评估。DataTable
未实例化。您的错误发生在:
<DataTable>.AsEnumerable()
来自反射器, System.Linq.Enumerable :
Public Shared Function AsEnumerable(Of TSource)(ByVal source As IEnumerable(Of TSource)) As IEnumerable(Of TSource)
Return source
End Function
<强>解决方案强>
的
Public Class FbuildingSettings
Public Sub New()
Me.InitializeComponent()
Me.camButtonDtable = New DataTable()
Me.camButtonDtable.Columns.Add("Building", GetType(String))
Me.camButtonDtable.AcceptChanges()
End Sub
Public ReadOnly camButtonDtable As DataTable
End Class
答案 1 :(得分:0)
最后找到解决方案(这是我使用过的):
FbuildingSettings.camButtonDtable = databaseFunctions.GetDataTable(queryBtn) 'to iniatialize data on cambtndtable
这应该是这样的(不太确定):
Dim queryBtn As String = "SELECT * FROM tblCameraButtons"
FbuildingSettings.camButtonDtable = <DataTable>.Fill(queryBtn)