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!