Hi there,
I have a combo box that contains 10 names. For eg. I select John's name. It will retrieve his left250 value from Access database. It will then display as a label. I've managed to do this so far. However, when i add in a new name in the database, the new name does not appear in the combo box. If I delete John's name in the database, the name in the combo box will not be deleted. Instead, when i select John when the program is running, it will show error. I guess i need to add in some codes for my combo box. Cos when i retrieve values, it will retrieve in reference to the selected index of the combo box. How do i update my combo box automatically without having to refresh my vb program?
Here's my codes:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\BIE\Sowmya.mdb;Jet OLEDB:Database Password=****"


sql = "SELECT * FROM thresholdTable"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Sowmya")


s = Me.nameComboBox.SelectedIndex
left250 = ds.Tables("Sowmya").Rows(s).Item("AC250L")
right250 = ds.Tables("Sowmya").Rows(s).Item("AC250R")

Me.Label1.Text = left250
Me.Label2.Text = right250

End Sub


The data set is a connectionless method of importing data that means that you will not be able to update it directly. Just recall the button1 through the button1.performclick and don't forget to clear the combo before refilling it. As I noticed you are only getting 2 values out of the dataset so what you can do to enhance performance is adjusting the SQL statment and including some conditions in it instead of retriving all values. (NB: you have posted a vb.net subject in vb6 area)

This article has been dead for over six months. Start a new discussion instead.