dataset / table / datagridview RRS feed

  • Question

  • Hi :)

    I have the following code, but the dgv don't show it - if file exists
    (WriteXml works fine)

    if (File.Exists(@"c:\file.DataSet"))
                    string DFile = @"c:\file.DataSet";

                dataGridView1.DataMember = DataTable.TableName;
                dataGridView1.DataSource = DataSet;

    What should I do?

    Any help would be great :)

    • Edited by PSB4ever Friday, July 10, 2009 8:00 PM
    Friday, July 10, 2009 7:57 PM


All replies

  • You need to instantiate your dataset.

    DataSet ds = new DataSet();
    Friday, July 10, 2009 8:23 PM
  • Can you be more specific on the issue?
     So does the data not show on the datagrid all the time, part of the time? If its all of the time, likely the file doesn't exist, put a breakpoint in to ensure a file is read

     Are you asking about if the columns not show up for when there is an empty DataSet? If a table is not instanciated then the columns will not show up.

    Are you getting an exception of some type? Would like to help but need to know more information.

    Another way you can debug this issue as well is by printing or messageboxing out the count of the rows in a datatable or all of them after they are loaded. If there are rows then this will indicate there are.

    Another thing to try is to set the dataSource property directly to the DataTable itself like so

    datagridview1.DataSource = DataSet.Tables["Mytable"];

    Let me know if anything helped

    Chris Robinson
    Program manager - dataSet
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, July 10, 2009 11:38 PM
  • Thank you for the answers.

    I solved the problem.

    The error was that DataMember has to be a string and the correct name ;)

    Saturday, July 11, 2009 9:56 AM