473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 2519
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bill | last post by:
I have have two list boxes. One is a listing of all possible variables. We'll call this listbox A. The other is a listing of all the selected variables. We'll call this listbox B. If a person...
1
by: Claire | last post by:
As a Listbox.item, rather than using a string I'm using a ListItems object, overriding the ToString method When I add items to listbox.items, my strings are shown correctly. On the otherhand, when...
1
by: MrNobody | last post by:
Hi, I'm doing something where I add custom objects to a ListBox which have aToString() method overriden so it displays what I want. When adding instances of these custom objects to the ListBox I...
1
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to...
6
by: =?Utf-8?B?S2Fp?= | last post by:
Hi all, using AJAX Toolkit with vb.net 2.0 how could I make this "Updating..." Screen like e.g. on Codeplex when you click on the "Vote" button...
2
by: julie18881 | last post by:
I may be being really stupid here, i have spent the last 3 hours looking round your site and some other for answers to my problem, but have not had much luck (possibly cuase my brain just isn't...
3
by: Reg Verrin | last post by:
I have a program that displays constantly changing prices which it sources from the web once per second. The prices are displayed on a Listbox (not the best choice but there are good reasons for...
1
by: Wavey | last post by:
Hi All, I have a problem with updating an Access database from a datatable. I have two rows of data in my database at the moment for testing, the first row is an ID number (primary key), the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.