xmlÓëDataSetµÄ»¥×ª»»Àà
ÒÔǰÔÚ²©¿ÍÉÏ·¢¹ý£¬¾ÈËÌáÐÑDataSetÒÑ×Ô´ø¶ÁдXMLµÄ¹¦ÄÜ£¬ÓÚÊDZãɾÁË£¬
²»¹ýÔÚʵ¼ùÖиоõ·â×°Ò»²ãºó£¬Ê¹ÓÃÆðÀ´»¹ÊÇÂù·½±ãµÄ¡£¹ÊÔÙ´ÎÖØ·¢¡£
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Xml;
namespace XmlDesign
{
class XmlDatasetConvert
{
//½«xml¶ÔÏóÄÚÈÝ×Ö·û´®×ª»»ÎªDataSet
public static DataSet ConvertXMLToDataSet(string xmlData)
{
StringReader stream = null;
XmlTextReader reader = null;
try
{
DataSet xmlDS = new DataSet();
stream = new StringReader(xmlData);
//´Óstream×°ÔØµ½XmlTextReader
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
return xmlDS;
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (reader != null) reader.Close();
}
}
//½«xmlÎļþת»»ÎªDataSet
public static DataSet ConvertXMLFileToDataSet(string xmlFile)
{
StringReader stream = null;
XmlTextReader reader = null;
try
{
XmlDocument xmld = new XmlDocument();
xmld.Load(xmlFile);
DataSet xmlDS = new DataSet();
stream = new StringReader(xmld.InnerXml);
//´Óstream×°ÔØµ½XmlTextReader
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
//xmlDS.ReadXml(xmlFile);
return xmlDS;
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (reader != null) reader.Close();
}
}
//½«DataSetת»»Îªxml¶ÔÏó×Ö·û´®
public static string ConvertDataSetToXML(DataSet xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
//´Óstream×°ÔØµ½XmlTextReader
writer = new XmlTextWriter(stream, Encoding.Unicode);
//ÓÃWriteXml·½·¨Ð´ÈëÎļþ.
xmlDS.WriteXml(writer);
int count = (int)stream.Length;
byte[] arr = new byte[count];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(arr, 0, count);
UnicodeEncoding utf = new UnicodeEncoding();
return utf.GetString(arr).Trim();
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (writer != null) writer.Close();
}
}
//½«DataSetת»»ÎªxmlÎļþ
public static void ConvertDataSetToXMLFile(Dat
Ïà¹ØÎĵµ£º
XMLÊÇÒ»ÏîÈÈÃŵļ¼Êõ¡£ËüÖ®ËùÒÔÄܹ»ÒýÆðÈËÃǵÄÐËȤ£¬Ò»¸öÖ÷ÒªµÄÔÒòÔÚÓÚËüÊ®·ÖµÄ¼òµ¥£¬ÈËÃÇ¿ÉÒÔºÜÈÝÒ×µØÀí½âºÍʹÓÃËü¡£Ã¿Ò»¸ö³ÌÐòÔ±¶¼ÄÜÇáÒ׵ؿ´¶®Ò»¸öXMLÎļþ£¬Àí½âËü°üº¬µÄÄÚÈÝ¡£
.NETÖаüº¬Á˺ܶàÖ§³ÖXMLµÄÀ࣬ÕâЩÀàʹµÃ³ÌÐòԱʹÓÃXML±à³Ì¾ÍÈçͬÀí½âXMLÎļþÒ»Ñù¼òµ¥¡£ÔÚÕâÆªÎÄÕÂÖУ¬ÎÒ½«¸ø³öÕâÑùµÄÒ»¸öÀàµÄʹÓÃʾÀý£¬Õ ......
Ò»¸öC# xml ÐòÁл¯´íÎó
Ê·¢ÏÖ³¡£º
xmlÐòÁл¯µÄÊý¾ÝÖд洢µÄ½ÚµãÊý¾ÝÊÇ
<Module>536870912</Module> £¨xmlÎļþÖУ©
¶ÔÓ¦µÄÀàÊôÐÔÊÇ
public short Module { get; set; } £¨C#ÀàÖУ©
ÐòÁл¯µÄ´úÂ룺
public static FMDSTimeSeriesDefinitio ......
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏ£º
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price& ......
USE Test
--Create 2 tables as an example
CREATE TABLE ExampleTable
(
[ID] int PRIMARY KEY
,[Name] nvarchar(256)
)
CREATE TABLE ExampleTable2
(
[ID] int PRIMARY KEY
,[Name] nvarchar(256)
)
----way1
SELECT *
from sys.objects [table]
WHERE
[Name] LIKE 'ExampleTable%'
FOR XML AUTO, ROOT ......
C#×é¼þ¿ª·¢ÈËÔ±
ʲôʱºòʹÓÃoverride£¿Ê²Ã´Ê±ºòʹÓÃnew? ʲô½Ðshadowing?
ÖØÐ´¸¸ÀàµÄ·½·¨µÄʱºòÓÃoverrideÒÔʵÏÖ¶à̬£¬µ±ÄãÏëÆÁ±Î¸¸Àà³ÉÔ±µÄʱºòʹÓÃnew£¬shadowing»ù±¾¾ÍÊÇnewÓëoverrideÇø±ðµÈһЩ·½ÃæµÄÎÊÌ⣬¸öÈËÈÏΪŪÇåoverrideÓënew¾ÍûÓбØÒªÌØÒ⿼ÂÇshadowing¡£
½âÊÍvirtual¡¢sealed¡¢overrideºÍabstractµÄ ......