none
Two DataGridViews using Same Database on same form RRS feed

  • Question

  • I am writing a bank statement reconcile program that is using 2 DataGridviews,
    The two DataGridviews will be connected to same DB and table
    What I want to accomplish is DGV1 to show Debits and DGV2 to show Credits.
    I want to Update one field in SAME DB and Table.
    I am using Visual Studio Professional 2013, Using Visual Basic.
    What would be the best Approach to accomplish this program using designer.

    Charlie Soroka

    Sunday, September 9, 2018 5:07 PM

Answers

  • Use BindingSource components.

    Bind one BindingSource to the dataset (DataSource) and table (DataMember) then bind the second BindingSource DataSource to the first BindingSource.  The DataMember of the second BindingSource is the name of the relationship in the DataSet that links the two tables.

    The DataGridViews are then each bound to the BindingSource components.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Sunday, September 9, 2018 5:12 PM
    Moderator
  • Thank you for your reply. I did a bind of 2nd BS TO 1st BS. I then selected the Data Member for 2nd

    BS and the only choice is None. Not sure on what to put in this drop down box?


    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Sunday, September 9, 2018 6:28 PM
  • I am using Access 2007 for Database

    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Sunday, September 9, 2018 6:32 PM
  • Is the 1st BS bound to the DataSet generated from the Access Database?  Is the relationship between the two tables defined in the DataSet?

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Sunday, September 9, 2018 9:59 PM
    Moderator
  • Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'RMS_ACC2DataSet.TR_GL' table. You can move, or remove it, as needed.
            Me.TA_ACC2.Debits(Me.DS_ACC2.TR_GL)
        End Sub
    End Class
    
    This is the code that was created using designer.
    I did a dump of database also.
    


    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Monday, September 10, 2018 1:38 AM
  • Looks like there is only one table from the database defined in the dataset.

    Open the dataset designer (double click the dataset file in the solution explorer) and then add the other table from the access database into the dataset.  Ensure the relationship is defined if it is not automatically created after adding the second table.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Monday, September 10, 2018 2:05 PM
    Moderator
  • Thank you for your reply, I am only using the one database and one table, the two grids will display debits on 1st DataGridView and only show Credits  on 2nd Datagridview. I have create the Credit & Debit query for each DGV. What I am having trouble with is how to assign the query to work with each DataGridView. The goal of the program is to do a reconcile of bank statements. Sorry that I was not clear on goal.

     

    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Monday, September 10, 2018 5:56 PM
  • Ah, sorry, my mistake.

    You will need two dataset instances on your form.  Then each binding source can use a separate instance of the DataSet and each instance can call a different adapter method to fill its table.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Monday, September 10, 2018 6:56 PM
    Moderator
  • I was unable to get it to work in designer, but I did get it to work outside of designer. Thanks for help.

    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Tuesday, September 11, 2018 4:09 AM

All replies

  • Use BindingSource components.

    Bind one BindingSource to the dataset (DataSource) and table (DataMember) then bind the second BindingSource DataSource to the first BindingSource.  The DataMember of the second BindingSource is the name of the relationship in the DataSet that links the two tables.

    The DataGridViews are then each bound to the BindingSource components.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Sunday, September 9, 2018 5:12 PM
    Moderator
  • Thank you for your reply. I did a bind of 2nd BS TO 1st BS. I then selected the Data Member for 2nd

    BS and the only choice is None. Not sure on what to put in this drop down box?


    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Sunday, September 9, 2018 6:28 PM
  • I am using Access 2007 for Database

    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Sunday, September 9, 2018 6:32 PM
  • Is the 1st BS bound to the DataSet generated from the Access Database?  Is the relationship between the two tables defined in the DataSet?

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Sunday, September 9, 2018 9:59 PM
    Moderator
  • Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'RMS_ACC2DataSet.TR_GL' table. You can move, or remove it, as needed.
            Me.TA_ACC2.Debits(Me.DS_ACC2.TR_GL)
        End Sub
    End Class
    
    This is the code that was created using designer.
    I did a dump of database also.
    


    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Monday, September 10, 2018 1:38 AM
  • Looks like there is only one table from the database defined in the dataset.

    Open the dataset designer (double click the dataset file in the solution explorer) and then add the other table from the access database into the dataset.  Ensure the relationship is defined if it is not automatically created after adding the second table.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Monday, September 10, 2018 2:05 PM
    Moderator
  • Thank you for your reply, I am only using the one database and one table, the two grids will display debits on 1st DataGridView and only show Credits  on 2nd Datagridview. I have create the Credit & Debit query for each DGV. What I am having trouble with is how to assign the query to work with each DataGridView. The goal of the program is to do a reconcile of bank statements. Sorry that I was not clear on goal.

     

    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Monday, September 10, 2018 5:56 PM
  • Ah, sorry, my mistake.

    You will need two dataset instances on your form.  Then each binding source can use a separate instance of the DataSet and each instance can call a different adapter method to fill its table.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Monday, September 10, 2018 6:56 PM
    Moderator
  • I was unable to get it to work in designer, but I did get it to work outside of designer. Thanks for help.

    Charlie Soroka

    • Marked as answer by sorokateam Tuesday, September 11, 2018 4:10 AM
    Tuesday, September 11, 2018 4:09 AM