Reputation: 1393
on FbuildingSettings.vb
- Form
Public camButtonDtable As DataTable
Then I used it in Fbuilding.vb
- Form
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
Pretty much do what I want, get each of the distinct data from a column. So I used that code in 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
I get the error:
Tried this : Public camButtonDtable As New DataTable
- it did compiled, but the comboBox does not display a thing.
What am I doing wrong?
Upvotes: 0
Views: 125
Reputation: 1393
Finally found the solution (this is the one I used):
FbuildingSettings.camButtonDtable = databaseFunctions.GetDataTable(queryBtn) 'to iniatialize data on cambtndtable
This should be something like this (not really sure):
Dim queryBtn As String = "SELECT * FROM tblCameraButtons"
FbuildingSettings.camButtonDtable = <DataTable>.Fill(queryBtn)
Upvotes: 0
Reputation: 9981
Cause
DataTable
is populated, but rater if the DataTable
is instantiated.DataTable
is not instantiated.Your error occurs at:
<DataTable>.AsEnumerable()
From reflector, System.Linq.Enumerable:
Public Shared Function AsEnumerable(Of TSource)(ByVal source As IEnumerable(Of TSource)) As IEnumerable(Of TSource)
Return source
End Function
Solution
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
Upvotes: 1