Results 1 to 13 of 13

Thread: DataGridView repeating extra row???

Hybrid View

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

    Re: DataGridView repeating extra row???

    Quote Originally Posted by blakemckenna View Post
    I know your suggesting one way, but their seems to be so many ways of doing 1 thing. Obviously, I wish to use the easiest and most efficient method, which in this case, I'm just not sure what that method is.
    The easiest method is data-binding. At it's simplest, as I think it would be in your case, it's one line of code: you assign the DataTable to the grid's DataSource and you're done. You can also configure data-binding to do much more if required.
    Quote Originally Posted by blakemckenna View Post
    As far as the counts go, after the fill, there are 3 rows in the DS.
    I believe that I asked for three different values and you've only provided one. If I ask a question it's for a reason. If you'd like me to help further then please provide the information I've asked for.
    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

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: DataGridView repeating extra row???

    jmc,

    I'm not using a DataTable. As far as the DGV rowcount, it's 4 and the last row is empty. Also, after looking at the DGV after it's been populated, here is what the columns equate to. This is just sample data.

    Code:
                  Col 1         Col 2         Col 3                Col 4         Col 5
     Row 1    00001         ABC, Inc.    (123) 456-7890          45459         OH
     Row 2    00001         ABC, Inc.    (222) 333-4444          90210         CA
     Row 3    00005         Test Co.       empty                     empty       empty
     Row 4    empty           empty        empty                     empty       empty
    As far as using a BindingSource, how do I set the datasource when the SQL statement is using 3 different tables?
    Last edited by blakemckenna; Mar 2nd, 2010 at 11:10 PM.
    Blake

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

    Re: DataGridView repeating extra row???

    Quote Originally Posted by blakemckenna View Post
    I'm not using a DataTable.
    You're filling a DataSet, getting an item from its Tables collection of that DataSet, then looping through the DataRows in that item's Rows collection. If the Rows collection of that table contains DataRows, what do you suppose the Tables collection of the DataSet contains? I suggest that you read this.
    Quote Originally Posted by blakemckenna View Post
    As far as the DGV rowcount, it's 4 and the last row is empty. Also, after looking at the DGV after it's been populated, here is what the columns equate to. This is just sample data.

    Code:
                  Col 1         Col 2         Col 3                Col 4         Col 5
     Row 1    00001     ABC, Inc.    (123) 456-7890    45459         OH
     Row 2    00001     ABC, Inc.    (222) 333-4444    90210         CA
     Row 3    00005     Test Co.       empty               empty       empty
     Row 4    empty       empty        empty               empty       empty
    Are you doing this on purpose? I've twice now asked for three values and you have still only provided two of them. If I ask someone for help and they ask me for more information, as a matter of course I either provide that information or an explanation of why I am unable to. I suggest that you adopt the same approach because otherwise you can really frustrate those who are trying to help. Making someone ask the same question three times is not the way to get a solution to your problem. Please tell me what the return value of your Fill call is.
    Quote Originally Posted by blakemckenna View Post
    As far as using a BindingSource, how do I set the datasource when the SQL statement is using 3 different tables?
    BindingSources have nothing to do with SQL statements. A BindingSource is simply an object that facilitates binding a list to one or more controls. How many lists do you have? You have one list. The fact that the data in that list came from three different database tables is of no concern to the BindingSource. It doesn't care where the data came from.
    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

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: DataGridView repeating extra row???

    There are only 2 row counts because I'm NOT using a DataTable. If this is to much trouble, just don't reply again.
    Blake

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

    Re: DataGridView repeating extra row???

    Quote Originally Posted by blakemckenna View Post
    There are only 2 row counts because I'm NOT using a DataTable. If this is to much trouble, just don't reply again.
    OK, you ARE using a DataTable. This:
    Code:
    For Each row As DataRow In rsClientGrid.Tables("tblClients").Rows
    is a DataTable. It contains DataRows and its in the Tables collection of a DataSet; what else would it be?

    Try reading what's posted:
    As for record counts, what is the return value of your Fill call? What is the value of the Rows.Count property of your DataTable? What is the value of the RowCount property of your DGV?
    You've answered the green question:
    As far as the counts go, after the fill, there are 3 rows in the DS.
    DataSets don't contain any rows. DataSets contains DataTables and DataRelations. The DataTables contain the DataRows. If there are 3 rows in the DataSet then those 3 rows are in your DataTable.

    You've answered the blue question:
    As far as the DGV rowcount, it's 4 and the last row is empty.
    You are yet to answer the red question. The red question has nothing to do with DataTables so whether you're using one or not is immaterial. All I'm asking for is the return value of the Fill method.

    Just so you know, that number will tell us exactly how many records are returned when the query is executed. Knowing the number of rows in the DataTable is all well and good but maybe two of those three rows were already there. If you tell me that Fill returns 3 then I can tell you that, if you expect your query to retrieve one row, it's your query that's faulty and you can stop looking elsewhere. If I ask for information I ask for it for a reason. If you want help solving your problem then why would you not provide it?
    Last edited by jmcilhinney; Mar 2nd, 2010 at 11:51 PM.
    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

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: DataGridView repeating extra row???

    I don't know how to get the "Fill" count? What do I need to do?
    Blake

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

    Re: DataGridView repeating extra row???

    Quote Originally Posted by blakemckenna View Post
    I don't know how to get the "Fill" count? What do I need to do?
    There we go. If you don't know then you don't know but if you don't say so then I don't know that you don't know. It just seems like you're ignoring my question.

    Fill is a function. You get its return value like you do any other function. This is from the MSDN documentation for the particular overload of OleDbDataAdapter.Fill that you're calling:
    Code:
    Dim instance As DbDataAdapter
    Dim dataSet As DataSet
    Dim srcTable As String
    Dim returnValue As Integer
    
    returnValue = instance.Fill(dataSet, srcTable)
    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

  8. #8
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: DataGridView repeating extra row???

    Also.
    Have you checked the SQL statement on SQL to see what it returns?
    Check the Left Joins they are tricky sometimes on the values they provide.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

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