Update the ComboBox at runtime???

Fiaolle

Member
Joined
Jun 14, 2006
Messages
8
Programming Experience
1-3
HiI have tried to update my combobox with no luck. I add records to the table,the combobox has as Datasource, but I don't know how to update the combobox.I have tried updata the OleDBAdapter and the DataSet and set the datasourceto that dataset, but nothing happens. I can see in the database that I'veadded a new record to the table, but nothing happens to the combobox when Iupdate it.Does anyone know how to solve this.I also don't know how to clear the ComboBox, I know that when I wan't to clear the DataGrid I use the code SetDataBinding(Nothing,Nothing). How do I clear a ComboBox?Please I need help!!Fia
 
Your wording and spelling is very bad. It would be nice if you edit your post a bit more precise and post some code as well.
 
Here is the code.

VB.NET:
Expand Collapse Copy
Private Sub btnChangeCombo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangeCombo.Click 
Dim data_adapter As New OleDbDataAdapter 
Dim command_builder As OleDbCommandBuilder 
Dim tableNamn As String 
Dim fgUpdateCommand As OleDbCommand = Conn.CreateCommand() 
Dim dr As DataRowView dr = Me.cmbVara.Items(cmbVaraSelIndex) fgUpdateCommand.CommandText = "Update Kött Set Kött=" & cmbVara.Text & "' where ID =" & dr.Row.ItemArray(0) 
strSQL = "select * from Kött" 
tableNamn = "Kött" 
data_adapter = New OleDbDataAdapter(strSQL, Conn)
data_adapter.Fill(dsVara, tableNamn) 
command_builder = New OleDbCommandBuilder(data_adapter) 
data_adapter.UpdateCommand = fgUpdateCommand 
Conn.Open() 
data_adapter.UpdateCommand.ExecuteNonQuery() 
Conn.Close() 
data_adapter.TableMappings.Add("Table", tableNamn) 
command_builder = New OleDbCommandBuilder(data_adapter) 
data_adapter.Update(dsVara) 
Me.cmbVara.DataSource = Nothing 
Me.cmbVara.DataSource = dsVara.Tables(tableNamn).DefaultView 
Me.cmbVara.DisplayMember = dsVara.Tables(tableNamn).Columns(1).ColumnName 
Me.cmbVara.ValueMember = dsVara.Tables(tableNamn).Columns(0).ColumnName 
Me.cmbVara.Update
End Sub

Fia
 
Last edited by a moderator:
Back
Top