|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
updating listbox with database updateI 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! erin.sebast***@cowaninsurancegroup.com wrote:
>Hello Everyone, If the application is for maintaining the data, why are you affecting >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) > > 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
Create a custom collection
How to re-acquire the Text from a combo box Anyone used Socketwrench? Problem With Insert into MySQL DB using VB.Net 2005 COBOL Packed decimal converter to VB decimal Capture and redirect TCP traffic computer properties in vb.net filewatcher file modification What mvp use for printing Random String |
|||||||||||||||||||||||