Hi, iv got this problem iv been trying to solve for some time now by looking at examples etc of others code. Basically i am inserting data from a access db table, to fill the data for a combo box. I have successfully done this using the following code, however im trying to find away to insert code that will remove the duplicates coming from the db table. This is probably very simple however i am a certified beginnner when it comes to programming so would very much appreciate any help from more experienced programmers
thanks alot
john
Here is the code (sorry about the indentation):
PrivateSub ReportHardwareProblem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
' Retrieve all the Hardware types in the table
' Dim AppPath As String = Mid(Application.ExecutablePath, 1, Len(Application.ExecutablePath) - 14)
Dim ConString AsString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=""ProblemDatabase.mdb"";"
Dim DBCon AsNew OleDb.OleDbConnection(ConString)
DBCon.Open()
Dim DSet AsNew DataSet, SQLStr AsString
Dim cmd As System.Data.OleDb.OleDbCommand
Dim dbAdaptr As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
With dbAdaptr
.TableMappings.Add("Table", "Companies")
SQLStr = "Select [Hardware_Type] from Hardware"
cmd = New System.Data.OleDb.OleDbCommand(SQLStr, DBCon)
cmd.CommandType = CommandType.Text
.SelectCommand = cmd
.Fill(DSet)
.Dispose()
EndWith
DSet.AcceptChanges()
tTbl = DSet.Tables.Item(0)
DSet.Dispose()
DBCon.Close()
' fill out array by Company Names for cboRightCombo combobox
cboHardwareType.Text = ""
cboHardwareType.Items.Clear()
cboHardwareType.BeginUpdate()
'Load the Company Names into the ComboBox Control
Dim index AsString
Dim Array() AsString
ForEach tRow In tTbl.Rows
cboHardwareType.Items.Add(tRow("Hardware_Type").ToString)
Next
cboHardwareType.EndUpdate()
EndSub
thanks alot
john
Here is the code (sorry about the indentation):
PrivateSub ReportHardwareProblem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
' Retrieve all the Hardware types in the table
' Dim AppPath As String = Mid(Application.ExecutablePath, 1, Len(Application.ExecutablePath) - 14)
Dim ConString AsString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=""ProblemDatabase.mdb"";"
Dim DBCon AsNew OleDb.OleDbConnection(ConString)
DBCon.Open()
Dim DSet AsNew DataSet, SQLStr AsString
Dim cmd As System.Data.OleDb.OleDbCommand
Dim dbAdaptr As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
With dbAdaptr
.TableMappings.Add("Table", "Companies")
SQLStr = "Select [Hardware_Type] from Hardware"
cmd = New System.Data.OleDb.OleDbCommand(SQLStr, DBCon)
cmd.CommandType = CommandType.Text
.SelectCommand = cmd
.Fill(DSet)
.Dispose()
EndWith
DSet.AcceptChanges()
tTbl = DSet.Tables.Item(0)
DSet.Dispose()
DBCon.Close()
' fill out array by Company Names for cboRightCombo combobox
cboHardwareType.Text = ""
cboHardwareType.Items.Clear()
cboHardwareType.BeginUpdate()
'Load the Company Names into the ComboBox Control
Dim index AsString
Dim Array() AsString
ForEach tRow In tTbl.Rows
cboHardwareType.Items.Add(tRow("Hardware_Type").ToString)
Next
cboHardwareType.EndUpdate()
EndSub