New Value added to Combo is not visible

G

Guest

Hi,

I have a databound Combo Box where I'm adding a new value to the database on
the Click of the button. I'm able to see the ComboText and it is writing to
the database. But when I do a refresh on the Combo I'm not able to see the
added value in the Combo.

Please assist. Below is the code where I'm adding the new value to the Combo.

---------------
Dim txtmodelname As String
txtmodelname = InputBox("Please select the model name")
cmbModel.Text = txtmodelname
Dim con As OleDbConnection
Dim cmd As OleDbCommand = New OleDbCommand
Dim da As OleDbDataAdapter
Dim sConStr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\db1.mdb"
Dim sqlStr As String = "Insert into Names (Name,Description,TypeId)
values (?,?,1)"
con = New OleDbConnection(sConStr)
cmd.Connection = con
'MsgBox(sqlStr)
cmd.Parameters.Add("Name", txtmodelname)
cmd.Parameters.Add("Description", txtmodelname)
cmd.CommandText = sqlStr
con.Open()
cmd.ExecuteNonQuery()
con.Close()
 
C

Cor Ligthert

Sindbaad,
cmbModel.Text = txtmodelname

When this is your adding of the combobox than it is easy to tell.
\\\
cmbModel.items.add(txtmodelname)
///

I hope this helps?

Cor
 
G

Guest

Hi Cor,

Thanks for your prompt suggestion.

I actually tried that option of adding the value to the Combo List. I got an
error saying "Cannot modify the Items collection when the DataSource property
is set.". As this is data bound I can't add cmbmodel.items.add()

Any suggestions.

Rgds,
Sindbaad
 
C

Cor Ligthert

SindBaad,

I first was writting that we cannot see how you add your items to the
combobox when I saw that textbox.text. So I thought that that was your entry
point.

So show what is the datasource. The proper way is than to add (or modify)
that row to the probably datatable. You are using a not normal way to update
when you are using a datatable (that is not really a problem before you
understand me wrong).

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top