Click here to Skip to main content
Rate this: bad
good
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"];
       dsFinalTimeTable.Tables.Add(tbldt);
and the Error is:
table' argument cannot be null. Parameter name: table
 
and it points to the following line
dsFinalTimeTable.Tables.Add(tbldt);
 
Thanks
Posted 26-Jul-10 4:37am
Edited 26-Jul-10 4:57am
v2
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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"];
  Permalink  
Comments
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 Sergey Alexandrovich Kryukov 586
1 OriginalGriff 311
2 Maciej Los 170
3 Mehdi Gholam 145
4 PIEBALDconsult 140
0 Sergey Alexandrovich Kryukov 11,384
1 OriginalGriff 5,783
2 Maciej Los 5,684
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web02 | 2.8.141030.1 | Last Updated 3 Aug 2010
Copyright © CodeProject, 1999-2014
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