Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# XML
Good Day ,
It has been a long day. here we go
tbldt = new DataTable("TIMETABLES");
       XmlDataDocument xmlDatadocTimeTable = new XmlDataDocument();
       xmlDatadocTimeTable.DataSet.ReadXml(@"C:\Pilot Project\App_Data\TimeTable_Full.xml");
       tbldt = (DataTable)xmlDatadocTimeTable.DataSet.Tables["TIMETABLES"];
and the Error is:
table' argument cannot be null. Parameter name: table
and it points to the following line
Posted 26-Jul-10 5:37am
Edited 26-Jul-10 5:57am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The new instance of the datatable set into "tbldt" is being reset by the line:
tbldt = (DataTable)xmlDatadocTimeTable.DataSet.Tables["TIMETABLES"];
I would check to make sure your file "TimeTable_Full.xml" indeed has the TIMETABLES table. Because it seems, it does not.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I agree with Andrew.
As a side note, you're wasting memory by declaring tbldt equal to a new DataTable.
You then change where tbldt is pointing to without disposing of the other table which AFAIK will keep the new DataTable in memory and you'll not be able to use that block.
Since you're setting tbldt to a DataTable, you don't need to create it as a new object. You also don't need to tell it that it is a DataTable. DataSet.Tables[stringValue] returns a DataTable; This is the way to do it:
DataTable tbldt;
tbldt = xmlDatadocTimeTable.DataSet.Tables["TIMETABLES"];
koool.kabeer at 27-Jul-10 2:26am
Exactly Perfect Answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Zoltán Zörgő 220
1 Sergey Alexandrovich Kryukov 205
2 Peter Leow 160
3 BillWoodruff 85
4 bling 80
0 Sergey Alexandrovich Kryukov 9,543
1 OriginalGriff 6,901
2 Peter Leow 4,737
3 Zoltán Zörgő 4,404
4 CHill60 2,932

Advertise | Privacy | Mobile
Web03 | 2.8.150129.1 | Last Updated 3 Aug 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100