468,135 Members | 1,394 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,135 developers. It's quick & easy.

updating listbox with database update

Hello Everyone,
I have created a small application in vb.net to maintain items in a
database the problem i am having is that once i delete/add/edit an
individual item the changes don't reflect in the listbox that displays
all records.

In my form load i have

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Dim dataRow As dataRow
Dim datacolumn As datacolumn
ds = New DataSet

cn = New OleDbConnection(constants.CONNECTIONSTRING)
'provider to be used when working with access database
cn.Open()

da = New OleDbDataAdapter("Select * FROM original", cn)

da.Fill(ds)

CreateBindings()

cn.Close()

Me.lstbxnames.DataSource = ds.Tables(0)
Me.lstbxnames.DisplayMember = "Operator"
Me.lstbxnames.ValueMember = "ID"
when i add/delete/edit i deal directly with the database and then i
have tried refreshing the dataset, refreshing the listbox but it won't
reflect the changes in the listbox unless i close the application and
then open it again. The edit code is as follows ( as reference, the
delete and add are very similar)

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim strSQL As String
Dim icount As Integer
Dim id As Integer

Try

cn = New OleDbConnection(constants.CONNECTIONSTRING)
'provider to be used when working with access database
cn.Open()

strSQL = "Update original set Operator = '" & txtName.Text
& "',Processor = " & System.Convert.ToInt32(txtProc.Text) & ",RAM = " &
System.Convert.ToInt32(txtRAM.Text) & ",hdd = " &
System.Convert.ToInt32(txthdd.Text) & ",Monitor = '" & txtMonitor.Text
& "',Device = '" & txtDevice.Text & "',Office = '" & txtOffice.Text &
"',OS = '" & txtOS.Text & "',serial = '" & txtserial.Text & "' where id
= " & System.Convert.ToInt32(Me.txtId.Text)
cmd = New OleDbCommand(strSQL, cn)

icount = cmd.ExecuteNonQuery

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cn.Close()
End Try
Thanks in advance!

Jan 10 '06 #1
1 2097
er************@cowaninsurancegroup.com wrote:
Hello Everyone,
I have created a small application in vb.net to maintain items in a
database the problem i am having is that once i delete/add/edit an
individual item the changes don't reflect in the listbox that displays
all records.
when i add/delete/edit i deal directly with the database and then i
have tried refreshing the dataset, refreshing the listbox but it won't
reflect the changes in the listbox unless i close the application and
then open it again. The edit code is as follows ( as reference, the
delete and add are very similar)

If the application is for maintaining the data, why are you affecting
the data outside of the application? Make the changes in a datagrid,
then populate those changes to the database.
Thanks in advance!


The other alternative, if you must do it this way, is to rebuild your
dataset after each database change, then rebind it to the listbox. I
recommend the other method.

Tom
Jan 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bill | last post: by
1 post views Thread by MrNobody | last post: by
1 post views Thread by Spock | last post: by
6 posts views Thread by =?Utf-8?B?S2Fp?= | last post: by
3 posts views Thread by Reg Verrin | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.