Results 1 to 5 of 5

Thread: [RESOLVED] please help with refreshing binding source

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Resolved [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?

  2. #2
    Addicted Member sauronsmatrix's Avatar
    Join Date
    Jun 2008
    Location
    USA
    Posts
    133

    Re: please help with refreshing binding source

    try:
    Code:
    dgviewname.Refresh()
    or
    Code:
    dgviewname.RefreshEdit()

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Resolved 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width