SQL递归(高分,急).

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL递归(高分,急).相关的知识,希望对你有一定的参考价值。

图中的表的PKId为主键,ParentId为外键,实现自我关联,这样就是递归是吗?
我搞不懂这样自我关联有什么好处,起什么作用?
谁给讲解一下。

这个估计PKId是ParentId的父节点吧
给你举个例子,就只用这两个字段吧,其他的也没多大用
PKId ParentId
1 0
2 0
3 1
4 2
5 1

假设数据是我上边这样的
可以假设每个PKId分别为商品大类,就把1的定义为软件吧,2定义为硬件,3为硬盘,4为ps软件,5为主板

这样的话,你就能看出对应关系了吧?
1和2是最高层的,所以无父节点,所以ParentId为0
3和5都是硬件,所以归属为1
4为软件,所以归属为2
这样的好处是减少多次读取其他表里的无用信息,在一定程度上可以提高效率,当然是指数据量大的时候,数据量小的时候基本没什么区别
作用你自己都说了,其实就是实现自我关联

但是这样有一点不好,在自身有主键外键,如果其中的逻辑关系弄的不太清楚的话,很容易出问题,简单来说就是这样了
参考技术A 这样有好处的,比如可以用来实现树状的论坛,主题帖子的ParentId为0,每一个回帖的ParentID为其回复的帖子(不一定都是主题)的PkId,这样的数据结构简单,程序功能强大(比如实现的论坛就不是简单的板状),使用也方便,比如要搜索的时候,不用在两个表里面查询。 参考技术B 不是递归,只是少了个表,和普通表一样。 参考技术C 用法介绍和操作手册如果你是完全安装的话,会一起安装到你的计算机上,那个介绍的非常全,比市面上任何一本书都全,叫“联机丛书”。从语法到控制台操作都有讲解步骤和实例的。
是这样的:(我这里以ORACLE9i为例)
1):如果你的ORACLE服务器端是装在另外一台电脑(服务器上),而客户端是装在自己的电脑上;那么你在自己电脑上安装PL/SQL Developer之后,每次登录都会弹出PL/SQL Developer登录框,要求你输入:
用户名:________ //登录服务器端数据库的用户名
口令:_______ //登录服务器端数据库的密码
数据库:________ //服务器端数据库的名称
连接为:Normal
至少我在公司使用是这种情况的,不知道你是不是把服务器端和客户端都装在你自己的电脑上了,如果是这样的话,可能是因为你已经登录过了,系统(你的电脑)自动将你的用户名和口令放在Cookies里了,这样每次登录就不需要输入用户名和口令了;否则如果你不输入用户名和密码登录的话,登录到PL/SQL Developer里,在标题栏里会显示PL/SQL Developer(没有登录),这样你是使用不了数据库里的数据的,明白吗?朋友!
2).Oracle的书籍我给你推荐几本:(有9i和10G)
1:Oracle 9i中文版基础培训教程
下载地址:
http://www.gougou.com/search?search=Oracle%209i%E4%B8%AD%E6%96%87%E7%89%88%E5%9F%BA%E7%A1%80%E5%9F%B9%E8%AE%AD%E6%95%99%E7%A8%8B&id=0
2:ORACLE10G入门与实践
http://www.gougou.com/search?search=ORACLE.10G%E5%85%A5%E9%97%A8%E4%B8%8E%E5%AE%9E%E8%B7%B5&restype=-1&id=10000000&ty=0
3:精通oracle 10g系统管理
http://www.gougou.com/search?search=%E7%B2%BE%E9%80%9Aoracle%2010g%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86&restype=-1&id=10000000&ty=0
4:另外还有视频教程也不错,叫‘Oracle 10G 数据库系统视频教程'
http://www.gougou.com/search?search=Oracle%2010G%20%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B3%BB%E7%BB%9F%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B&restype=-1&id=10000000&ty=0
----上面都是我自己自学下载过的,还有很多你可以在百度或迅雷里下载的(全部是PDF格式的)应该现在也可以下载的。
祝你工作顺利、事业进步!!用hibernate 连接 sql server2000数据库,配置文件
<hibernate-mapping>
<class name="com.pqsite.NNXLT.DB.SysUserMessage" table="SYS_USER_MESSAGE" schema="dbo" catalog="QPWorld">
<id name="msgId" type="java.lang.Integer">
<column name="MSG_ID" />
<generator class="identity" />
</id>

<property name="sndId" type="java.lang.Integer">
<column name="SND_ID" />
</property>
<property name="sndName" type="java.lang.String">
<column name="SND_NAME" length="150" />
</property>
<property name="rcvId" type="java.lang.Integer">
<column name="RCV_ID" />
</property>
<property name="rcvName" type="java.lang.String">
<column name="RCV_NAME" length="150" />
</property>
<property name="msgTitle" type="java.lang.String">
<column name="MSG_TITLE" length="150" />
</property>
<property name="msgContent" type="java.lang.String">
<column name="MSG_CONTENT" length="150" />
</property>
<property name="msgTime" type="java.util.Date">
<column name="MSG_TIME" length="23" />
</property>
</class>
</hibernate-mapping>
提示 [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]无法将 NULL 值插入列 'MSG_ID',表 'QPWorld.dbo.SYS_USER_MESSAGE';该列不允许空值。INSERT 失败。
那个知道?
MSG_ID是主键
主键是不能为空的,插入数据前要检查该字段值是否为空
参考技术D 自引用,没有实质约束。只是便於查看关系

(高分求助)怎么用C#语言实现串口通讯,需要程序,急!

调用API实现,最好是不用控件,需要源程序!急
总共就这么多分,希望高手能帮忙!谢谢

☆★○●◎◇◆□℃‰?■△▲※→←↑↓〓☆★○●◎◇◆□℃‰?■△▲※→←↑↓〓☆★○●◎◇◆□℃‰?■△▲※→←↑↓〓☆★○●◎◇◆□℃‰?■△▲※→←↑↓〓
通常,在C#中实现串口通信,我们有四种方法:

第一:通过MSCOMM控件这是最简单的,最方便的方法。可功能上很难做到控制自如,同时这个控件并不是系统本身所带,所以还得注册。可以访问
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=320
一个外国人写的教程
第二:微软在.NET新推出了一个串口控件,基于.NET的P/Invoke调用方法实现,详细的可以访问微软网站
Serial Comm
Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications

http://msdn.microsoft.com/msdnmag/issues/02/10/netserialcomm/
第三:就是用第三方控件啦,可一般都要付费的,不太合实际,何况楼主不喜欢,不作考虑
第四:自己用API写串口通信,这样难度高点,但对于我们来说,可以方便实现自己想要的各种功能。

我们采用第四种方法来实现串口通信,用现成的已经封装好的类库,常见两个串口操作类是JustinIO和SerialStreamReader。介绍JustinIO的使用方法:

打开串口:

函数原型:public void Open()

说明:打开事先设置好的端口

示例:

using JustinIO;

static JustinIO.CommPort ss_port = new JustinIO.CommPort();
ss_port.PortNum = COM1; //端口号
ss_port.BaudRate = 19200; //串口通信波特率
ss_port.ByteSize = 8; //数据位
ss_port.Parity = 0; //奇偶校验
ss_port.StopBits = 1;//停止位
ss_port.ReadTimeout = 1000; //读超时
try

if (ss_port.Opened)

ss_port.Close();
ss_port.Open(); //打开串口

else

ss_port.Open();//打开串口

return true;

catch(Exception e)

MessageBox.Show("错误:" + e.Message);
return false;


写串口:

函数原型:public void Write(byte[] WriteBytes)

WriteBytes 就是你的写入的字节,注意,字符串要转换成字节数组才能进行通信

示例:

ss_port.Write(Encoding.ASCII.GetBytes("AT+CGMI\r")); //获取手机品牌

读串口:

函数原型:public byte[] Read(int NumBytes)

NumBytes 读入缓存数,注意读取来的是字节数组,要实际应用中要进行字符转换

示例:

string response = Encoding.ASCII.GetString(ss_port.Read(128)); //读取128个字节缓存

关闭串口:

函数原型:ss_port.Close()

示例:

ss_port.Close();

整合代码:
using System;
using System.Runtime.InteropServices;

namespace JustinIO
class CommPort

public int PortNum;
public int BaudRate;
public byte ByteSize;
public byte Parity; // 0-4=no,odd,even,mark,space
public byte StopBits; // 0,1,2 = 1, 1.5, 2
public int ReadTimeout;

//comm port win32 file handle
private int hComm = -1;

public bool Opened = false;

//win32 api constants
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const int OPEN_EXISTING = 3;
private const int INVALID_HANDLE_VALUE = -1;

[StructLayout(LayoutKind.Sequential)]
public struct DCB
//taken from c struct in platform sdk
public int DCBlength; // sizeof(DCB)
public int BaudRate; // current baud rate
/* these are the c struct bit fields, bit twiddle flag to set
public int fBinary; // binary mode, no EOF check
public int fParity; // enable parity checking
public int fOutxCtsFlow; // CTS output flow control
public int fOutxDsrFlow; // DSR output flow control
public int fDtrControl; // DTR flow control type
public int fDsrSensitivity; // DSR sensitivity
public int fTXContinueOnXoff; // XOFF continues Tx
public int fOutX; // XON/XOFF out flow control
public int fInX; // XON/XOFF in flow control
public int fErrorChar; // enable error replacement
public int fNull; // enable null stripping
public int fRtsControl; // RTS flow control
public int fAbortOnError; // abort on error
public int fDummy2; // reserved
*/
public uint flags;
public ushort wReserved; // not currently used
public ushort XonLim; // transmit XON threshold
public ushort XoffLim; // transmit XOFF threshold
public byte ByteSize; // number of bits/byte, 4-8
public byte Parity; // 0-4=no,odd,even,mark,space
public byte StopBits; // 0,1,2 = 1, 1.5, 2
public char XonChar; // Tx and Rx XON character
public char XoffChar; // Tx and Rx XOFF character
public char ErrorChar; // error replacement character
public char EofChar; // end of input character
public char EvtChar; // received event character
public ushort wReserved1; // reserved; do not use


[StructLayout(LayoutKind.Sequential)]
private struct COMMTIMEOUTS
public int ReadIntervalTimeout;
public int ReadTotalTimeoutMultiplier;
public int ReadTotalTimeoutConstant;
public int WriteTotalTimeoutMultiplier;
public int WriteTotalTimeoutConstant;


[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;


[DllImport("kernel32.dll")]
private static extern int CreateFile(
string lpFileName, // file name
uint dwDesiredAccess, // access mode
int dwShareMode, // share mode
int lpSecurityAttributes, // SD
int dwCreationDisposition, // how to create
int dwFlagsAndAttributes, // file attributes
int hTemplateFile // handle to template file
);
[DllImport("kernel32.dll")]
private static extern bool GetCommState(
int hFile, // handle to communications device
ref DCB lpDCB // device-control block
);
[DllImport("kernel32.dll")]
private static extern bool BuildCommDCB(
string lpDef, // device-control string
ref DCB lpDCB // device-control block
);
[DllImport("kernel32.dll")]
private static extern bool SetCommState(
int hFile, // handle to communications device
ref DCB lpDCB // device-control block
);
[DllImport("kernel32.dll")]
private static extern bool GetCommTimeouts(
int hFile, // handle to comm device
ref COMMTIMEOUTS lpCommTimeouts // time-out values
);
[DllImport("kernel32.dll")]
private static extern bool SetCommTimeouts(
int hFile, // handle to comm device
ref COMMTIMEOUTS lpCommTimeouts // time-out values
);
[DllImport("kernel32.dll")]
private static extern bool ReadFile(
int hFile, // handle to file
byte[] lpBuffer, // data buffer
int nNumberOfBytesToRead, // number of bytes to read
ref int lpNumberOfBytesRead, // number of bytes read
ref OVERLAPPED lpOverlapped // overlapped buffer
);
[DllImport("kernel32.dll")]
private static extern bool WriteFile(
int hFile, // handle to file
byte[] lpBuffer, // data buffer
int nNumberOfBytesToWrite, // number of bytes to write
ref int lpNumberOfBytesWritten, // number of bytes written
ref OVERLAPPED lpOverlapped // overlapped buffer
);
[DllImport("kernel32.dll")]
private static extern bool CloseHandle(
int hObject // handle to object
);
[DllImport("kernel32.dll")]
private static extern uint GetLastError();

public void Open()

DCB dcbCommPort = new DCB();
COMMTIMEOUTS ctoCommPort = new COMMTIMEOUTS();

// OPEN THE COMM PORT.

hComm = CreateFile("COM" + PortNum ,GENERIC_READ | GENERIC_WRITE,0, 0,OPEN_EXISTING,0,0);

// IF THE PORT CANNOT BE OPENED, BAIL OUT.
if(hComm == INVALID_HANDLE_VALUE)
throw(new ApplicationException("Comm Port Can Not Be Opened"));


// SET THE COMM TIMEOUTS.

GetCommTimeouts(hComm,ref ctoCommPort);
ctoCommPort.ReadTotalTimeoutConstant = ReadTimeout;
ctoCommPort.ReadTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(hComm,ref ctoCommPort);

// SET BAUD RATE, PARITY, WORD SIZE, AND STOP BITS.
GetCommState(hComm, ref dcbCommPort);
dcbCommPort.BaudRate=BaudRate;
dcbCommPort.flags=0;
//dcb.fBinary=1;
dcbCommPort.flags|=1;
if (Parity>0)

//dcb.fParity=1
dcbCommPort.flags|=2;

dcbCommPort.Parity=Parity;
dcbCommPort.ByteSize=ByteSize;
dcbCommPort.StopBits=StopBits;
if (!SetCommState(hComm, ref dcbCommPort))

//uint ErrorNum=GetLastError();
throw(new ApplicationException("Comm Port Can Not Be Opened"));

//unremark to see if setting took correctly
//DCB dcbCommPort2 = new DCB();
//GetCommState(hComm, ref dcbCommPort2);
Opened = true;



public void Close()
if (hComm!=INVALID_HANDLE_VALUE)
CloseHandle(hComm);


public byte[] Read(int NumBytes)
byte[] BufBytes;
byte[] OutBytes;
BufBytes = new byte[NumBytes];
if (hComm!=INVALID_HANDLE_VALUE)
OVERLAPPED ovlCommPort = new OVERLAPPED();
int BytesRead=0;
ReadFile(hComm,BufBytes,NumBytes,ref BytesRead,ref ovlCommPort);
OutBytes = new byte[BytesRead];
Array.Copy(BufBytes,OutBytes,BytesRead);

else
throw(new ApplicationException("Comm Port Not Open"));

return OutBytes;


public void Write(byte[] WriteBytes)
if (hComm!=INVALID_HANDLE_VALUE)
OVERLAPPED ovlCommPort = new OVERLAPPED();
int BytesWritten = 0;
WriteFile(hComm,WriteBytes,WriteBytes.Length,ref BytesWritten,ref ovlCommPort);

else
throw(new ApplicationException("Comm Port Not Open"));







由于篇幅,以及串口通信涉及内容广泛,我在这里只讲这些。
参考技术A //
//bool XmlTextReader.Read(): 读取流中下一个节点,当读完最后一个节点再次调用该方法该方法返回false
//XmlNodeType XmlTextReader.NodeType: 该属性返回当前节点的类型
// XmlNodeType.Element 元素节点
// XmlNodeType.EndElement 结尾元素节点
// XmlNodeType.XmlDeclaration 文档的第一个节点
// XmlNodeType.Text 文本节点
//bool XmlTextReader.HasAttributes: 当前节点有没有属性,返回true或false
//string XmlTextReader.Name: 返回当前节点的名称
//string XmlTextReader.Value: 返回当前节点的值
//string XmlTextReader.LocalName: 返回当前节点的本地名称
//string XmlTextReader.NamespaceURI: 返回当前节点的命名空间URI
//string XmlTextReader.Prefix: 返回当前节点的前缀
//bool XmlTextReader.MoveToNextAttribute(): 移动到当前节点的下一个属性
//---------------------------------------------------------------------------------------------------

namespace XMLReading

using System;
using System.Xml;
using System.Windows.Forms;
using System.ComponentModel;

/// <summary>
/// Xml文件读取器
/// </summary>

public class XmlReader : IDisposable

private string _xmlPath;
private const string _errMsg = "Error Occurred While Reading ";
private ListBox _listBox;
private XmlTextReader xmlTxtRd;

#region XmlReader 的构造器

public XmlReader()

this._xmlPath = string.Empty;
this._listBox = null;
this.xmlTxtRd = null;


/// <summary>
/// 构造器
/// </summary>
/// <param name="_xmlPath">xml文件绝对路径</param>
/// <param name="_listBox">列表框用于显示xml</param>

public XmlReader(string _xmlPath, ListBox _listBox)

this._xmlPath = _xmlPath;
this._listBox = _listBox;
this.xmlTxtRd = null;


#endregion
#region XmlReader 的资源释放方法

/// <summary>
/// 清理该对象所有正在使用的资源

/// </summary>

public void Dispose()

this.Dispose(true);
GC.SuppressFinalize(this);


/// <summary>
/// 释放该对象的实例变量
/// </summary>
/// <param name="disposing"></param>

protected virtual void Dispose(bool disposing)

if (!disposing)
return;
if (this.xmlTxtRd != null)

this.xmlTxtRd.Close();
this.xmlTxtRd = null;


if (this._xmlPath != null)

this._xmlPath = null;



#endregion
#region XmlReader 的属性

/// <summary>
/// 获取或设置列表框用于显示xml
/// </summary>

public ListBox listBox

get

return this._listBox;

set

this._listBox = value;



/// <summary>
/// 获取或设置xml文件的绝对路径
/// </summary>

public string xmlPath

get

return this._xmlPath;

set

this._xmlPath = value;



#endregion

/// <summary>
/// 遍历Xml文件
/// </summary>

public void EachXml()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

this._listBox.Items.Add(this.xmlTxtRd.Value);


catch(XmlException exp)

throw new XmlException(_errMsg + this._xmlPath + exp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取Xml文件的节点类型
/// </summary>

public void ReadXmlByNodeType()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

this._listBox.Items.Add(this.xmlTxtRd.NodeType.ToString());


catch(XmlException exp)

throw new XmlException(_errMsg + this._xmlPath + exp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 根据节点类型过滤Xml文档
/// </summary>
/// <param name="xmlNType">XmlNodeType 节点类型的数组</param>

public void FilterByNodeType(XmlNodeType[] xmlNType)

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);
try

while(xmlTxtRd.Read())

for (int i = 0; i < xmlNType.Length; i++)

if (xmlTxtRd.NodeType == xmlNType[i])

this._listBox.Items.Add(xmlTxtRd.Name + " is Type " + xmlTxtRd.NodeType.ToString());




catch(XmlException exp)

throw new XmlException(_errMsg + this.xmlPath + exp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取Xml文件的所有文本节点值

/// </summary>

public void ReadXmlTextValue()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

if (xmlTxtRd.NodeType == XmlNodeType.Text)

this._listBox.Items.Add(xmlTxtRd.Value);



catch(XmlException xmlExp)

throw new XmlException(_errMsg + this._xmlPath + xmlExp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取Xml文件的属性
/// </summary>

public void ReadXmlAttributes()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

if (xmlTxtRd.NodeType == XmlNodeType.Element)

if (xmlTxtRd.HasAttributes)

this._listBox.Items.Add("The Element " + xmlTxtRd.Name + " has " + xmlTxtRd.AttributeCount + " Attributes");

this._listBox.Items.Add("The Attributes are:");

while(xmlTxtRd.MoveToNextAttribute())

this._listBox.Items.Add(xmlTxtRd.Name + " = " + xmlTxtRd.Value);


else

this._listBox.Items.Add("The Element " + xmlTxtRd.Name + " has no Attribute");

this._listBox.Items.Add("");



catch(XmlException xmlExp)

throw new XmlException(_errMsg + this._xmlPath + xmlExp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取Xml文件的命名空间
/// </summary>

public void ReadXmlNamespace()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);
try

while(xmlTxtRd.Read())

if (xmlTxtRd.NodeType == XmlNodeType.Element && xmlTxtRd.Prefix != "")

this._listBox.Items.Add("The Prefix " + xmlTxtRd.Prefix + " is associated with namespace " + xmlTxtRd.NamespaceURI);

this._listBox.Items.Add("The Element with the local name " + xmlTxtRd.LocalName + " is associated with" + " the namespace " + xmlTxtRd.NamespaceURI);


if (xmlTxtRd.NodeType == XmlNodeType.Element && xmlTxtRd.HasAttributes)

while(xmlTxtRd.MoveToNextAttribute())

if (xmlTxtRd.Prefix != "")

this._listBox.Items.Add("The Prefix " + xmlTxtRd.Prefix + " is associated with namespace " + xmlTxtRd.NamespaceURI);

this._listBox.Items.Add("The Attribute with the local name " + xmlTxtRd.LocalName + " is associated with the namespace " + xmlTxtRd.NamespaceURI);






catch(XmlException xmlExp)

throw new XmlException(_errMsg + this._xmlPath + xmlExp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取整个Xml文件
/// </summary>

public void ReadXml()

string attAndEle = string.Empty;
this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

if (xmlTxtRd.NodeType == XmlNodeType.XmlDeclaration)
this._listBox.Items.Add(string.Format("<?0 1 ?>",xmlTxtRd.Name,xmlTxtRd.Value));
else if (xmlTxtRd.NodeType == XmlNodeType.Element)

attAndEle = string.Format("<0 ",xmlTxtRd.Name);
if (xmlTxtRd.HasAttributes)

while(xmlTxtRd.MoveToNextAttribute())

attAndEle = attAndEle + string.Format("0='1' ",xmlTxtRd.Name,xmlTxtRd.Value);



attAndEle = attAndEle.Trim() + ">";
this._listBox.Items.Add(attAndEle);

else if (xmlTxtRd.NodeType == XmlNodeType.EndElement)
this._listBox.Items.Add(string.Format("</0>",xmlTxtRd.Name));
else if (xmlTxtRd.NodeType == XmlNodeType.Text)
this._listBox.Items.Add(xmlTxtRd.Value);


catch(XmlException xmlExp)

throw new XmlException(_errMsg + this._xmlPath + xmlExp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();





窗体代码如下:

namespace XMLReading



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Xml;

public class Form1 : System.Windows.Forms.Form



private System.Windows.Forms.ListBox listBox1;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.Button button3;

private System.Windows.Forms.Button button4;

private System.Windows.Forms.Button button5;

private System.Windows.Forms.Button button6;

private System.Windows.Forms.Button button7;

private string xmlPath;

private XmlReader xRead;

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()



InitializeComponent();



/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )



if( disposing )



if (components != null)



components.Dispose();





base.Dispose( disposing );



#region Windows 窗体设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()



this.listBox1 = new System.Windows.Forms.ListBox();

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.button3 = new System.Windows.Forms.Button();

this.button4 = new System.Windows.Forms.Button();

this.button5 = new System.Windows.Forms.Button();

this.button6 = new System.Windows.Forms.Button();

this.button7 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// listBox1

//

this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.listBox1.ItemHeight = 12;

this.listBox1.Location = new System.Drawing.Point(8, 8);

this.listBox1.Name = "listBox1";

this.listBox1.Size = new System.Drawing.Size(716, 460);

this.listBox1.TabIndex = 0;

//

// button1

//

this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));

this.button1.Location = new System.Drawing.Point(8, 488);

this.button1.Name = "button1";

this.button1.TabIndex = 1;

this.button1.Text = "Example1";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// button2

//

this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));

this.button2.Location = new System.Drawing.Point(96, 488);

this.button2.Name = "button2";

this.button2.TabIndex = 2;

this.button2.Text = "Example2";

this.button2.Click += new System.EventHandler(this.button2_Click);

//

// button3

//

this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));

this.button3.Location = new System.Drawing.Point(648, 488);

this.button3.Name = "button3";

this.button3.TabIndex = 3;

this.button3.Text = "Example7";

this.button3.Click += new System.EventHandler(this.button3_Click);

//

// button4

//

this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));

this.button4.Location = new System.Drawing.Point(184, 488);

this.button4.Name = "button4";

this.button4.TabIndex = 4;

this.button4.Text = "Example3";

this.button4.Click += new System.EventHandler(this.button4_Click);

//

// button5

//

this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));

this.button5.Location = new System.Drawing.Point(272, 488);

this.button5.Name = "button5";

this.button5.TabIndex = 5;

this.button5.Text = "Example4";

this.button5.Click += new System.EventHandler(this.button5_Click);

//

// button6

//

this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));

this.button6.Location = new System.Drawing.Point(360, 488);

this.button6.Name = "button6";

this.button6.TabIndex = 6;

this.button6.Text = "Example5";

this.button6.Click += new System.EventHandler(this.button6_Click);

//

// button7

//

this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));

this.button7.Location = new System.Drawing.Point(448, 488);

this.button7.Name = "button7";

this.button7.TabIndex = 7;

this.button7.Text = "Example6";

this.button7.Click += new System.EventHandler(this.button7_Click);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(728, 517);

this.Controls.Add(this.button7);

this.Controls.Add(this.button6);

this.Controls.Add(this.button5);

this.Controls.Add(this.button4);

this.Controls.Add(this.button3);

this.Controls.Add(this.button2);

this.Controls.Add(this.button1);

this.Controls.Add(this.listBox1);

this.Name = "Form1";

this.Text = "XMLReader";

this.ResumeLayout(false);

//

// xmlPath

//

this.xmlPath = "sample.xml";



#endregion

/// <summary>

/// 应用程序的主入口点。

/// </summary>

[STAThread]

static void Main()



Application.Run(new Form1());



private void button1_Click(object sender, System.EventArgs e)



xRead = new XmlReader(this.xmlPath,this.listBox1);

try



xRead.EachXml();



catch(XmlException xmlExp)



MessageBox.Show(xmlExp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



catch(Exception exp)



MessageBox.Show(exp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



finally



xRead.Dispose();





private void button2_Click(object sender, System.EventArgs e)



xRead = new XmlReader(this.xmlPath,this.listBox1);

try



xRead.ReadXmlByNodeType();



catch(XmlException xmlExp)



MessageBox.Show(xmlExp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



catch(Exception exp)



MessageBox.Show(exp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



finally



xRead.Dispose();





private void button3_Click(object sender, System.EventArgs e)



XmlNodeType[] xmlNType = XmlNodeType.Element, XmlNodeType.EndElement, XmlNodeType.XmlDeclaration;

xRead = new XmlReader(this.xmlPath, this.listBox1);

try



xRead.FilterByNodeType(xmlNType);



catch(XmlException xmlExp)



MessageBox.Show(xmlExp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



catch(Exception exp)



MessageBox.Show(exp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



finally



xRead.Dispose();





private void button4_Click(object sender, System.EventArgs e)



xRead = new XmlReader(this.xmlPath, this.listBox1);

try



xRead.ReadXmlTextValue();



catch(XmlException xmlExp)



MessageBox.Show(xmlExp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



catch(Exception exp)



MessageBox.Show(exp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



finally



xRead.Dispose();





private void button5_Click(object sender, System.EventArgs e)



xRead = new XmlReader(this.xmlPath, this.listBox1);

try



xRead.ReadXmlAttributes();



catch(XmlException xmlExp)



MessageBox.Show(xmlExp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



catch(Exception exp)



MessageBox.Show(exp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



finally



xRead.Dispose();





private void button6_Click(object sender, System.EventArgs e)



xRead = new XmlReader(this.xmlPath, this.listBox1);

try



xRead.ReadXmlNamespace();



catch(XmlException xmlExp)



MessageBox.Show(xmlExp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



catch(Exception exp)



MessageBox.Show(exp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



finally



xRead.Dispose();





private void button7_Click(object sender, System.EventArgs e)



xRead = new XmlReader(this.xmlPath, this.listBox1);

try



xRead.ReadXml();



catch(XmlException xmlExp)



MessageBox.Show(xmlExp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



catch(Exception exp)



MessageBox.Show(exp.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);



finally



xRead.Dispose();







参考技术B //
//bool XmlTextReader.Read(): 读取流中下一个节点,当读完最后一个节点再次调用该方法该方法返回false
//XmlNodeType XmlTextReader.NodeType: 该属性返回当前节点的类型
// XmlNodeType.Element 元素节点
// XmlNodeType.EndElement 结尾元素节点
// XmlNodeType.XmlDeclaration 文档的第一个节点
// XmlNodeType.Text 文本节点
//bool XmlTextReader.HasAttributes: 当前节点有没有属性,返回true或false
//string XmlTextReader.Name: 返回当前节点的名称
//string XmlTextReader.Value: 返回当前节点的值
//string XmlTextReader.LocalName: 返回当前节点的本地名称
//string XmlTextReader.NamespaceURI: 返回当前节点的命名空间URI
//string XmlTextReader.Prefix: 返回当前节点的前缀
//bool XmlTextReader.MoveToNextAttribute(): 移动到当前节点的下一个属性
//---------------------------------------------------------------------------------------------------

namespace XMLReading

using System;
using System.Xml;
using System.Windows.Forms;
using System.ComponentModel;

/// <summary>
/// Xml文件读取器
/// </summary>

public class XmlReader : IDisposable

private string _xmlPath;
private const string _errMsg = "Error Occurred While Reading ";
private ListBox _listBox;
private XmlTextReader xmlTxtRd;

#region XmlReader 的构造器

public XmlReader()

this._xmlPath = string.Empty;
this._listBox = null;
this.xmlTxtRd = null;


/// <summary>
/// 构造器
/// </summary>
/// <param name="_xmlPath">xml文件绝对路径</param>
/// <param name="_listBox">列表框用于显示xml</param>

public XmlReader(string _xmlPath, ListBox _listBox)

this._xmlPath = _xmlPath;
this._listBox = _listBox;
this.xmlTxtRd = null;


#endregion
#region XmlReader 的资源释放方法

/// <summary>
/// 清理该对象所有正在使用的资源

/// </summary>

public void Dispose()

this.Dispose(true);
GC.SuppressFinalize(this);


/// <summary>
/// 释放该对象的实例变量
/// </summary>
/// <param name="disposing"></param>

protected virtual void Dispose(bool disposing)

if (!disposing)
return;
if (this.xmlTxtRd != null)

this.xmlTxtRd.Close();
this.xmlTxtRd = null;


if (this._xmlPath != null)

this._xmlPath = null;



#endregion
#region XmlReader 的属性

/// <summary>
/// 获取或设置列表框用于显示xml
/// </summary>

public ListBox listBox

get

return this._listBox;

set

this._listBox = value;



/// <summary>
/// 获取或设置xml文件的绝对路径
/// </summary>

public string xmlPath

get

return this._xmlPath;

set

this._xmlPath = value;



#endregion

/// <summary>
/// 遍历Xml文件
/// </summary>

public void EachXml()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

this._listBox.Items.Add(this.xmlTxtRd.Value);


catch(XmlException exp)

throw new XmlException(_errMsg + this._xmlPath + exp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取Xml文件的节点类型
/// </summary>

public void ReadXmlByNodeType()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

this._listBox.Items.Add(this.xmlTxtRd.NodeType.ToString());


catch(XmlException exp)

throw new XmlException(_errMsg + this._xmlPath + exp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 根据节点类型过滤Xml文档
/// </summary>
/// <param name="xmlNType">XmlNodeType 节点类型的数组</param>

public void FilterByNodeType(XmlNodeType[] xmlNType)

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);
try

while(xmlTxtRd.Read())

for (int i = 0; i < xmlNType.Length; i++)

if (xmlTxtRd.NodeType == xmlNType[i])

this._listBox.Items.Add(xmlTxtRd.Name + " is Type " + xmlTxtRd.NodeType.ToString());




catch(XmlException exp)

throw new XmlException(_errMsg + this.xmlPath + exp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取Xml文件的所有文本节点值

/// </summary>

public void ReadXmlTextValue()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

if (xmlTxtRd.NodeType == XmlNodeType.Text)

this._listBox.Items.Add(xmlTxtRd.Value);



catch(XmlException xmlExp)

throw new XmlException(_errMsg + this._xmlPath + xmlExp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取Xml文件的属性
/// </summary>

public void ReadXmlAttributes()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

if (xmlTxtRd.NodeType == XmlNodeType.Element)

if (xmlTxtRd.HasAttributes)

this._listBox.Items.Add("The Element " + xmlTxtRd.Name + " has " + xmlTxtRd.AttributeCount + " Attributes");

this._listBox.Items.Add("The Attributes are:");

while(xmlTxtRd.MoveToNextAttribute())

this._listBox.Items.Add(xmlTxtRd.Name + " = " + xmlTxtRd.Value);


else

this._listBox.Items.Add("The Element " + xmlTxtRd.Name + " has no Attribute");

this._listBox.Items.Add("");



catch(XmlException xmlExp)

throw new XmlException(_errMsg + this._xmlPath + xmlExp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取Xml文件的命名空间
/// </summary>

public void ReadXmlNamespace()

this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);
try

while(xmlTxtRd.Read())

if (xmlTxtRd.NodeType == XmlNodeType.Element && xmlTxtRd.Prefix != "")

this._listBox.Items.Add("The Prefix " + xmlTxtRd.Prefix + " is associated with namespace " + xmlTxtRd.NamespaceURI);

this._listBox.Items.Add("The Element with the local name " + xmlTxtRd.LocalName + " is associated with" + " the namespace " + xmlTxtRd.NamespaceURI);


if (xmlTxtRd.NodeType == XmlNodeType.Element && xmlTxtRd.HasAttributes)

while(xmlTxtRd.MoveToNextAttribute())

if (xmlTxtRd.Prefix != "")

this._listBox.Items.Add("The Prefix " + xmlTxtRd.Prefix + " is associated with namespace " + xmlTxtRd.NamespaceURI);

this._listBox.Items.Add("The Attribute with the local name " + xmlTxtRd.LocalName + " is associated with the namespace " + xmlTxtRd.NamespaceURI);






catch(XmlException xmlExp)

throw new XmlException(_errMsg + this._xmlPath + xmlExp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();



/// <summary>
/// 读取整个Xml文件
/// </summary>

public void ReadXml()

string attAndEle = string.Empty;
this._listBox.Items.Clear();
this.xmlTxtRd = new XmlTextReader(this._xmlPath);

try

while(xmlTxtRd.Read())

if (xmlTxtRd.NodeType == XmlNodeType.XmlDeclaration)
this._listBox.Items.Add(string.Format("<?0 1 ?>",xmlTxtRd.Name,xmlTxtRd.Value));
else if (xmlTxtRd.NodeType == XmlNodeType.Element)

attAndEle = string.Format("<0 ",xmlTxtRd.Name);
if (xmlTxtRd.HasAttributes)

while(xmlTxtRd.MoveToNextAttribute())

attAndEle = attAndEle + string.Format("0='1' ",xmlTxtRd.Name,xmlTxtRd.Value);



attAndEle = attAndEle.Trim() + ">";
this._listBox.Items.Add(attAndEle);

else if (xmlTxtRd.NodeType == XmlNodeType.EndElement)
this._listBox.Items.Add(string.Format("</0>",xmlTxtRd.Name));
else if (xmlTxtRd.NodeType == XmlNodeType.Text)
this._listBox.Items.Add(xmlTxtRd.Value);


catch(XmlException xmlExp)

throw new XmlException(_errMsg + this._xmlPath + xmlExp.ToString());

finally

if (this.xmlTxtRd != null)
this.xmlTxtRd.Close();





窗体代码如下:

namespace XMLReading



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Xml;

public class Form1 : System.Windows.Forms.Form



private System.Windows.Forms.ListBox listBox1;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.Button button3;

private System.Windows.Forms.Button button4;

private System.Windows.Forms.Button button5;

private System.Windows.Forms.Button button6;

private System.Windows.Forms.Button button7;

private string xmlPath;

private XmlReader xRead;

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()



InitializeComponent();



/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )



if( disposing )



if (components != null)



components.Dispose();





base.Dispose( disposing );



#region Windows 窗体设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()



this.listBox1 = new System.Windows.Forms.ListBox();

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.button3 = new System.Windows.Forms.Button();

this.button4 = new System.Windows.Forms.Button();

this.button5 = new System.Windows.Forms.Button();

this.button6 = new System.Windows.Forms.Button();

this.button7 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// listBox1

//

this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.listBox1.ItemHeight = 12;

this.list
参考技术C 和vb一样都是控件!
先安个vb,然后你进c#,添加控件。添加com那种。里面就有mscomm了。用他一切ok。
你要是用2005版的就不必麻烦了。2005在.net框架2.0下已经有自己的了,不用在用com了。幸福。。。
不过我还没转过去呢。在等破解的。
参考技术D Baidu,Google搜一下看看。

以上是关于SQL递归(高分,急).的主要内容,如果未能解决你的问题,请参考以下文章

高分求解SQL题目 急!!!

急,sqlserver外键问题【高分】

急!matlab怎么算如下递归问题!!

现在要查询一个字段至少包括两个中文字,高分急求SQL语句,谢谢~~~

sql server 中如何查询学生表中每位学生全部科目中最高分对应的那行数据呢? 急急急 !

高分求解,急!!!Java连接Oracle10g 问题 java.sql.SQLException: 无法从套接字读取更多的数据