Home > Net >  Data table serialization problems
Data table serialization problems

Time:02-16

Data table serialized using class file code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Xml;
Using System, Xml Serialization;
Using System. IO;


The namespace WindowsFormsApp1
{
The class DataToXml
{
Public static bool CDataToXmlFile (DataTable dt, string xmlFilePath)
{
If ((dt!=null) & amp; & (! String. IsNullOrEmpty (xmlFilePath)))
{
String path=Application. StartupPath;

MemoryStream ms=null;
XmlTextWriter XmlWt=null;
Try
{
Ms=new MemoryStream ();
//according to ms instantiation XmlWt
XmlWt=new XmlTextWriter (ms, Encoding. Unicode);
//retrieve data from the ds
Dt. WriteXml (XmlWt);
Int count=(int) ms. Length;
Byte [] temp=new byte (count);
Ms. Seek (0, SeekOrigin. Begin);
Ms. Read (temp, 0, count);
//returns the Unicode text
UnicodeEncoding ucode=new UnicodeEncoding ();
//write file
StreamWriter sw=new StreamWriter (path);
Sw. WriteLine (" & lt; ? The XML version="1.0" encoding="utf-8"? & gt;" );
Sw. WriteLine (ucode. Get string (temp). The Trim ());
Sw. The Close ();
return true;
}
The catch (System. Exception ex)
{
Throw the ex.
}
The finally
{
//release resources
If (XmlWt!=null)
{
XmlWt. Close ();
Ms. Close ();
Ms. The Dispose ();
}
}
}
The else
{
return false;
}
}
}
}

The calling code:
String xmlFilePath=wenjian. XML;
DataToXml. CDataToXmlFile (dt, xmlFilePath);

The abnormal information, compiled according to the following statements incorrect:
Sw. WriteLine (" & lt; ? The XML version="1.0" encoding="utf-8"? & gt;" );


Severity code shows the project file line prohibits display status
CS1003 grammar errors, should input ", "WindowsFormsApp1 D: \ \ WindowsFormsApp1 data table operation \ WindowsFormsApp1 \ DataToXml cs 38 activity

Severity code shows the project file line prohibits display status
Error CS0246 failed to find the type or namespace name "DataTable" (whether the lack of a using directive or assembly reference?) WindowsFormsApp1 D: \ \ WindowsFormsApp1 \ WindowsFormsApp1 data table operation \ DataToXml cs 15 activities of

Baidu once, CS1003 may be asp.net application errors, WindowsFormsApp cannot use asp.net application?
CS0246 may be due to the use of data table but lack of reference,
  •  Tags:  
  • C#
  • Related