• I wasn't sure where exactly I should post this, but here it goes anyway... by the way, the solution to this could be really simple!

    I have a Generic list of strings.

    List<String> columnsList = new List<String>();

    As part of a method call, I accept it as a parameter - so the assumption from this point on is that the list is already intialized. I use this list to filter a limited number of columns from a table:

    DataTable dt = myDataSet.Tables[0].DefaultView.ToTable(false, columnsList.ToArray());

    This throws an ArgumentException: Column '' does not belong to underlying table 'Table'.

    However, when I explicitly pass in a new static array of strings, everything works fine:

    String[] columns = new String[] { "LastName", "FirstName", "SSN" };
    DataTable dt = myDataSet.Tables[0].DefaultView.ToTable(false, columns);

    Can anyone point out what am I doing wrong with the Generic list. Or point me in the right direction so that I can make the list of columns dynamic. Thanks.
    Tuesday, January 29, 2008 1:03 AM

All replies

  •  .NETPhreak wrote:

    This throws an ArgumentException: Column '' does not belong to underlying table 'Table'.

    The exception says that your table does not contain a column named '', i.e., an empty string. Is it possible that your list contains an empty string (see what columnList.ToArray() returns).

    Tuesday, January 29, 2008 5:13 AM
  • That was the first thing I looked for, Gregor. It is really weird. I thought it was just a long day... I have come back to it, and it still does the same thing. I was able to find a similar post via Google, and someone had mentioned it was a bug in the TS version of Visual Studio. But then I am using VS2005 Pro...
    Tuesday, January 29, 2008 6:10 AM
  • And what if you convert the List<string> to string[] manually and use this array in a ToTable(...) call?
    Sorry for asking obvious questions, but this is really so weird. I too am using  VS2005 pro without SPs and was able to define new table based on the list of columns.
    Tuesday, January 29, 2008 8:59 AM
  • Was able to fix this following the tips in the other thread I mentioned before. Deleted the solution file, and virtually recreated the entire project, as well as the code files. I guess I may have missed the actual cause during the transition, but I may also have stumbled upon a genuine VS bug?

    Nevertheless, it seems to have fixed itself. Thanks for the input, Gregor.
    Tuesday, January 29, 2008 7:32 PM