将XmlReader与SQL Server的FOR XML AUTO问题一起使用 [英] Using XmlReader with SQL Server’s FOR XML AUTO Problem

查看:115
本文介绍了将XmlReader与SQL Server的FOR XML AUTO问题一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将XmlReader与SQL Server的FOR XML AUTO一起使用

我收到此代码:



受保护的 Sub Page_Load(< span style ="color:blue"> ByVal 发​​件人作为 对象 ByVal e As EventArgs)

Using XmlReader with SQL Server’s FOR XML AUTO

I got this code:

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim objConn 作为 SqlConnection(ConfigurationManager.ConnectionStrings(" db2ConnectionString" )。ConnectionString)

    Dim objConn As New SqlConnection(ConfigurationManager.ConnectionStrings("db2ConnectionString").ConnectionString)

objConn.Open()

    objConn.Open()

Dim objCmd 作为 SqlCommand(" select * from employees for xml auto" ,objConn)

    Dim objCmd As New SqlCommand("select * from employees for xml auto", objConn)

Dim xr As System.Xml.XmlReader = objCmd.ExecuteXmlReader()

    Dim xr As System.Xml.XmlReader = objCmd.ExecuteXmlReader()

Response.Write(" 所有员工姓名列表

"

    Response.Write("List of All Employee Names

"
)

xr.Read

    While xr.Read

Response.Write(xr( " ename" )& "
"

      Response.Write(xr("ename") & "
"
)

< span style ="font-size:10pt; font-family:'Courier New'"> 结束 while

    End While

xr.Close()

    xr.Close()

xr = Nothing

    xr = Nothing

objCmd.Dispose()

    objCmd.Dispose()

objCmd = 没什么

    objCmd = Nothing

objConn.Close()

    objConn.Close()

objConn = Nothing

    objConn = Nothing

推荐答案

Well xr(" ename)试图访问名为"ename"的属性。是否存在取决于您尝试从中读取数据的表(例如员工)的列名。假设Northwind数据库名为Employees的表没有名为ename的列,但它有名为FirstName和LastName的列,您可以按如下方式读出:




Code Snippet


这篇关于将XmlReader与SQL Server的FOR XML AUTO问题一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆