DataSet.Tables[0]

  • Thread starter Thread starter Sathyaish
  • Start date Start date
S

Sathyaish

We are required to send our weekly timesheets by Friday morning. I
sometimes forget to send them until Friday evening, if I am reminded,
or by the next Monday.

To solve my problem, I am writing a quick and dirty utility that will
mail timesheets out of a specific folder every Friday 9 AM whether I am
on my seat or not. It's fun.

I am keeping the list of timesheet files I have already sent in an XML
file. On program start up, I load it into a dataset and then into a
hashtable and then I dispose the dataset. Here's the code snippet under
discussion:


string sFile =
ConfigurationSettings.AppSettings["AlreadySentTimeSheetsDataSet"];
if ( !File.Exists( sFile ) )
return;

DataSet ds = new DataSet();
ds.ReadXml(sFile);
if (ds.Tables.Count > 0)
if ( ds.Tables[0] != null)
for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++)
_alreadySentTimeSheets.Add(ds.Tables[0].Rows[0],
ds.Tables[0].Rows[0]);


The problem is that the dataset does not contain any tables. The XML
file does have 25 records and is well formed and valid.
 
Please ignore this question. There was an error in my XML. I was too
much in a hurry to post this question before checking.
 
I would still create a "strongly typed dataset" object.

They're easier to deal with.


HEre is one I use:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="ExceptionLogDS"
targetNamespace="http://tempuri.org/ExceptionLogDS.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://tempuri.org/ExceptionLogDS.xsd"
xmlns:mstns="http://tempuri.org/ExceptionLogDS.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="ExceptionLogDS" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Exception">
<xs:complexType>
<xs:sequence>
<xs:element name="ExceptionMessage" type="xs:string" minOccurs="0" />
<xs:element name="ExceptionType" type="xs:string" minOccurs="0" />
<xs:element name="ExceptionDateTime" type="xs:dateTime" minOccurs="0"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>


the the code to add new entries:

mine is kludgey, but shows simple WriteXml methods.


private void SaveErrorDataSet(ExceptionLogDS ds , Exception ex)
{
if (null!=ds)
{
string uuid = System.Guid.NewGuid().ToString();
string xmlfileName = uuid + ".xml";
string exceptionFileName = uuid + ".log";


if (this.m_errorOutputDirectory.Length > 0 )
{
if (!System.IO.Directory.Exists(this.m_errorOutputDirectory))
{
System.IO.Directory.CreateDirectory(this.m_errorOutputDirectory);
}


xmlfileName = this.m_errorOutputDirectory + @"\" + xmlfileName;
exceptionFileName = this.m_errorOutputDirectory + @"\" +
exceptionFileName;
}
ds.WriteXml(xmlfileName);

DataSets.ExceptionLogDS exDS = new
GranadaCoder.Applications.BulkDataTransferExample.DataSets.ExceptionLogDS
();
exDS.Exception.AddExceptionRow(ex.Message , ex.GetType().ToString() ,
DateTime.Now );
exDS.WriteXml(exceptionFileName);




}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top