none
DataSet doesn't work properly (no entries in dataGridView). RRS feed

  • Question

  • HI. I have this problem... I have connected a database(TaskDates) to my winform project and now i have TaskDatesDataSet.xsd file in my solution explorer... In my code i have

     

    DataTable table = new TaskDatesDataSet.DatesDataTable();//Dates is one of tables in TaskDates database, it already contains some rows                                                                                               //and some rows it already contains
    mydataGridView1.DataSource = table;
    

     

    The problem is that I don't get any rows in mydataGridView1(only one row with DateID=-1; Date="")(DateID and Date are columns of Dates table)...

    Can anybody help me?


    • Edited by artxach Saturday, September 10, 2011 4:31 PM
    Saturday, September 10, 2011 4:30 PM

Answers

  • I tried to show table.Rows.Count in a MessageBox and got 0 rows. But when i open my table in SQL Server Management studio, there are 4 rows in it.

    And I have another question...

    When we connect to our database in visual studio, the programm automatically generates TaskDatesDataSet.xsd, and if we can use it to get our tables and do work with them, in that case why do we need SqlConnection, SqlAdapter... Is this another way to do the same, because when I try to get information using SqlConnection, SqlAdapter, SqlCommand... my project works properly:I get my four rows in the table.

    Thank You beforehand...


    • Edited by artxach Sunday, September 11, 2011 4:45 AM
    • Marked as answer by artxach Wednesday, September 14, 2011 7:06 PM
    Sunday, September 11, 2011 4:44 AM
  • The TableAdapters that can get generated when a DataSet is generated from an .xsd, are nothing more than wrappers around the SqlDataAdapter, SqlCommand etc., which actually do all the work, so you're better off (in my opinion) using the the SqlDataAdapter to begin with. Supposedly TableAdapters were supposed to make it all easier, but I think they've made it more confusing.

    Check out my 3-part series on Data Access for some ideas of making it all a bit simpler by not using TableAdapters. You may, or may not, want to re-work your existing app, but at least keep some of this in mind for any future work you do:

    http://geek-goddess-bonnie.blogspot.com/2009/09/dataaccess-part-i.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html

    Each post adds extra complexity to the Data Access classes, but more flexiblity. The first post is enough to get you going in the right direction and give you a general idea of the concept, but the second post is more useful. The third post gets into using anonymous delegates and may be too much for a beginner. In the first post is a link to my rant against TableAdapters, which in turn has a link to a post that describes how to create Typed DataSet .xsd's without TableAdapters.


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Edited by BonnieBMVP Sunday, September 11, 2011 3:01 PM
    • Marked as answer by artxach Wednesday, September 14, 2011 7:06 PM
    Sunday, September 11, 2011 3:01 PM

All replies

  • Have you verified whether or not you have more than one row in your table? Put a breakpoint on the mydataGridView1.DataSource line and check the contents of the table variable with the DataSet Viewer (or even a simple table.Rows.Count in the Immediate window).
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Sunday, September 11, 2011 12:09 AM
  • I tried to show table.Rows.Count in a MessageBox and got 0 rows. But when i open my table in SQL Server Management studio, there are 4 rows in it.

    And I have another question...

    When we connect to our database in visual studio, the programm automatically generates TaskDatesDataSet.xsd, and if we can use it to get our tables and do work with them, in that case why do we need SqlConnection, SqlAdapter... Is this another way to do the same, because when I try to get information using SqlConnection, SqlAdapter, SqlCommand... my project works properly:I get my four rows in the table.

    Thank You beforehand...


    • Edited by artxach Sunday, September 11, 2011 4:45 AM
    • Marked as answer by artxach Wednesday, September 14, 2011 7:06 PM
    Sunday, September 11, 2011 4:44 AM
  • The TableAdapters that can get generated when a DataSet is generated from an .xsd, are nothing more than wrappers around the SqlDataAdapter, SqlCommand etc., which actually do all the work, so you're better off (in my opinion) using the the SqlDataAdapter to begin with. Supposedly TableAdapters were supposed to make it all easier, but I think they've made it more confusing.

    Check out my 3-part series on Data Access for some ideas of making it all a bit simpler by not using TableAdapters. You may, or may not, want to re-work your existing app, but at least keep some of this in mind for any future work you do:

    http://geek-goddess-bonnie.blogspot.com/2009/09/dataaccess-part-i.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html

    Each post adds extra complexity to the Data Access classes, but more flexiblity. The first post is enough to get you going in the right direction and give you a general idea of the concept, but the second post is more useful. The third post gets into using anonymous delegates and may be too much for a beginner. In the first post is a link to my rant against TableAdapters, which in turn has a link to a post that describes how to create Typed DataSet .xsd's without TableAdapters.


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Edited by BonnieBMVP Sunday, September 11, 2011 3:01 PM
    • Marked as answer by artxach Wednesday, September 14, 2011 7:06 PM
    Sunday, September 11, 2011 3:01 PM