[RESOLVED] please help with refreshing binding source
hi everyone. im not sure if i should post this here or what but heres my question: i have a main form with a combo-box that is connected to a binding source (a microsoft access table). in a dialog, i let the user add/delete items in the table. how do i refresh the binding source on my original form to reflect the changes.
oh, and i insert data into my table by using the following sub:
Code:
Public Sub InsertMe(ByVal MyQuerrys As String)
On Error GoTo errorhandler
Dim conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\MyDb.mdb;Persist Security Info=True;Jet OLEDB:Database Password=")
Dim Cmd As OleDbCommand
Dim objCmd As New OleDbCommand
Cmd = New OleDbCommand(MyQuerrys, conn)
conn.Open()
objCmd = New OleDbCommand(MyQuerrys, conn)
objCmd.ExecuteNonQuery()
conn.Close()
If Not (Cmd Is Nothing) Then Cmd.Dispose()
Cmd = Nothing
If Not (objCmd Is Nothing) Then objCmd.Dispose()
objCmd = Nothing
errorhandler:
If Err.Number = 0 Then
ElseIf Err.Number = 5 Then
MsgBox("You have an item with that name already. Type a unique identifier")
Else
MsgBox(Err.Number)
End If
End sub
the data gets entered, and will show when i restart the app. but only after i restart it. ive also tried to just add the data to the combobox but it wont let me as its bound to a table. is it possible to unbind a control programatically?
Re: please help with refreshing binding source
try:
Code:
dgviewname.Refresh()
or
Code:
dgviewname.RefreshEdit()
Re: please help with refreshing binding source
no, it didnt work. i believe the refresh command just redraws the dialog, it doest refresh the data source
Re: please help with refreshing binding source
You don't have to refresh the BindingSource. It happens automatically when you make changes to the underlying list, which is the whole point of binding in the first place. If the user is adding and deleting records then you should be adding rows to, or deleting them form, the DataTable that you bound to the BindingSource in the first place. The rest is taken care of for you. If it wasn't, data-binding would be a waste of time.
Re: please help with refreshing binding source
well, after days of screwing around with this, i was able to make the update. im sure this isnt the best way to do it, but its what i got. for anyone who's interested:
after calling my sub to run the sql querry, i put this
Code:
Dim MyNewDS As New MyDataSet()
Dim staff As MyDataSet.tblStaffDataTable = MyNewDS.tblStaff
Dim newstaff As MyDataSet.tblStaffRow = staff.NewtblStaffRow
staff.Rows.Add(newstaff)
Form1.TblStaffTableAdapter.Fill(Form1.MyDataSet.tblStaff)
staff= Form1.TblStaffTableAdapter.GetData
Form1.ComboBox1.DataSource = staff