English 中文(简体)
将XML档案内容列入查阅数据库的错误
原标题:Error during insert the XML file content into an access database

在网络应用中,即希望将XML文档内容插入一个检索数据库,即代码(下文),但与这一行文有错误。

 xmlFile = XmlReader.Create("Product.xml", New XmlReaderSettings())

错误

“entergraph

请研究以下守则,并告诉我如何修改,从网络应用根数中获取“产品.xml”。 i) 试验“产品/产品”,不工作

Imports Microsoft.VisualBasic
Imports System.Xml

Imports System.Data.OleDb
Imports System.Data

Public Class Form1

    Public Shared Sub mimi()

    Dim connetionString As String

    Dim connection As OleDbConnection

    Dim command As OleDbCommand

    Dim ds As New DataSet

    Dim xmlFile As XmlReader

    Dim sql As String
    Dim adpter As New OleDbDataAdapter




    Dim product_ID As Integer

    Dim Product_Name As String

    Dim product_Price As Double



    connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |datadirectory|CRF.mdb;Persist Security Info=True"

    connection = New OleDbConnection(connetionString)



    xmlFile = XmlReader.Create("Product.xml", New XmlReaderSettings())

    ds.ReadXml(xmlFile)

    Dim i As Integer

    connection.Open()

    For i = 0 To ds.Tables(0).Rows.Count - 1

        product_ID = Convert.ToInt32(ds.Tables(0).Rows(i).Item(0))

        Product_Name = ds.Tables(0).Rows(i).Item(1)

        product_Price = Convert.ToDouble(ds.Tables(0).Rows(i).Item(2))

        sql = "insert into Product values(" & product_ID & ", " & Product_Name & " ," & product_Price & ")"

        command = New OleDbCommand(sql, connection)

        adpter.InsertCommand = command

        adpter.InsertCommand.ExecuteNonQuery()

    Next

    connection.Close()

End Sub

End Class
最佳回答

尝试使用HttpContext.Current.Server.MapPath(“~/Product.xml”)

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签