Xml.XmlDataDocument()过时的消息

时间:2012-12-07 17:03:12

标签: javascript xml visual-studio-2010

我正在运行一个简单的程序,在其中输入用户编号到文本框中,单击提交按钮,然后程序应该转到数据库查找您输入的数字并显示该行信息。很简单。 问题是我不断收到Xml.XmlDataDocument()过时的错误。我用谷歌搜索了这个问题,这导致我到了这里,但建议的替代品在我的程序中不起作用。 另外,我还没有学过VB,这是一个XML类。 我已经仔细检查了我的代码是否有任何错误,看不到任何内容。但是,我可能会错过森林的树木。想有另一组眼睛看看我的代码,看看我是否遗漏了什么,或者提供了Xml.XmlDataDocument()行的替代品。 提前感谢您提供任何帮助。

以下是我正在使用的代码:

onClick事件的Javascript

<script language="javascript" type="text/javascript">

        function btnSearch_onclick() {
            var docSubmit = new ActiveXObject("MSXML2.DOMDocument");
            docSubmit.loadXML("<?xml version='1.0'?><request><customerID>" + txtCustID.value + "</customerID></request>")


            var objSocket = new ActiveXObject("MSXML2.XMLHTTP");
            objSocket.open("POST", "Lookup.aspx", false)
            objSocket.send(docSubmit)
            alert(objSocket.responseXML.xml)

            lblFirstName.innerHTML = objSocket.responseXML.selectSingleNode("//FirstName").firstChild.nodeValue
            lblLastName.innerHTML = objSocket.responseXML.selectSingleNode("//LastName").firstChild.nodeValue
            lblAddress.innerHTML = objSocket.responseXML.selectSingleNode("//Address").firstChild.nodeValue
            lblCity.innerHTML = objSocket.responseXML.selectSingleNode("//City").firstChild.nodeValue
            lblState.innerHTML = objSocket.responseXML.selectSingleNode("//State").firstChild.nodeValue
            lblZip.innerHTML = objSocket.responseXML.selectSingleNode("//Zip").firstChild.nodeValue

        }
    </script>

这是VB代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim docReceived As New System.Xml.XmlDataDocument()
        docReceived.Load(Request.InputStream)

        Dim CustomerID = docReceived.SelectSingleNode("//customerID").FirstChild.Value

        Dim myConnection As New System.Data.OleDb.OleDbConnection
        Dim myConnectionString As String
        myConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & _
        Server.MapPath("customer.mbd")
        myConnection.ConnectionString = myConnectionString

        Dim strSQL As String
        strSQL = "Select * From CustomerInfo where CustomerID = " & CustomerID

        Dim myAdapter As New System.Data.OleDb.OleDbDataAdapter(strSQL, myConnection)

        Dim myDataSet As New System.Data.DataSet("CustomerInfo")

        Dim intRecords As Integer
        intRecords = myAdapter.Fill(myDataSet, "Customer")

        Response.ContentType = "text/xml"

        If intRecords > 0 Then
            myDataSet.WriteXml(Response.OutputStream)
        Else
            Response.Write("<?xml version='1.0'?><customer><FirstName>Not Found</FirstName><LastName>***</LastName><Address>***</Address><City>***</City><State>***</State><Zip>***</Zip><Phone>***</Phone><Email>***</Email></customer>")
        End If

        myDataSet.WriteXml(Response.OutputStream)

        myConnection.Close()
        myAdapter.Dispose()
        myConnection.Dispose()

    End Sub

1 个答案:

答案 0 :(得分:0)

XmlDataSet已过时。正如您在msdn上看到的那样,它甚至可能会在下一版本的.NET Framework中被删除([ObsoleteAttribute(“XmlDataDocument类将在未来的版本中删除。”)] )。在你的情况下,我认为你根本不需要它。简单修复似乎只是使用XmlDocument。我相信您不必更改代码中的任何其他内容,但这一行

Dim docReceived As New System.Xml.XmlDataDocument()

于:

Dim docReceived As New System.Xml.XmlDocument()