I have a ms access database that I am retrieving the database from and storing into a structure. Next I'm trying to populate the comboboxes with the values in the structured array but comes up blank.
Code:
Public Class frmMain
'Declared an empty array of structure
Dim Info(-1) As AutoData
''' <summary>
''' Structure holds Auto information
''' </summary>
''' <remarks>Implemented in array</remarks>
Structure Autodata
Public strMake As String
Public strModel As String
Public intYear As Integer
Public strCityMpg As String
Public strHywayMpg As String
Public strPrice As String
End Structure
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Me.Hide()
frmResults.ShowDialog()
Me.Close()
End Sub
Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Call LoadData()
End Sub
Private Sub LoadData()
'declare instance of new class
Dim AutoData As New clsConnect
'passes string from global module
AutoData.Connectionstring = mdlGlobal.strConnection
'Passes SQL command
AutoData.SQL = "SELECT ID, Make, Model, Year, CityMpg, HighwayMpg, EstimatedPrice FROM tblAuto" _
& " ORDER BY Make, Year"
'Clear out array contents
ReDim Info(-1)
cboMake.Items.Clear()
cboModel.Items.Clear()
cboYear.Items.Clear()
ListBox1.Items.Clear()
'Loops through the database, stores into the structure and displays in the listbox
For i As Integer = 0 To AutoData.ds.Tables(0).Rows.Count - 1
ReDim Preserve Info(Info.Length)
With Info(Info.Length - 1)
.strMake = AutoData.ds.Tables(0).Rows(i).Item("Make").ToString
.strModel = AutoData.ds.Tables(0).Rows(i).Item("Model").ToString
.intYear = AutoData.ds.Tables(0).Rows(i).Item("Year")
.strCityMpg = AutoData.ds.Tables(0).Rows(i).Item("CityMpg").ToString
.strHywayMpg = AutoData.ds.Tables(0).Rows(i).Item("HighwayMpg").ToString
.strPrice = AutoData.ds.Tables(0).Rows(i).Item("EstimatedPrice").ToString
ListBox1.Items.Add(.intyear)
cboMake.SelectedIndex = .strMake
cboModel.SelectedIndex = .strModel
cboYear.SelectedIndex = .intYear
End With
Next
End Sub
End Class