asp.net, vb.net. 목표는 XML 데이터를 테이블 (customerDetail)로 복사하는 것이지만 저장 프로 시저를 실행할 때 XML 데이터가 테이블에 복사되지 않고 오류가 발생하지 않습니다.
내 xml 파일 :
<?xml version="1.0" standalone="yes"?>
<q:Customers xmlns="http://quakeml.org/xmlns/bed/1.2" xmlns:catalog="http://anss.org/xmlns/catalog/0.1" xmlns:q="http://quakeml.org/xmlns/quakeml/1.2">
<Customer Id ="1">
<Name>John Hammond</Name>
<Country>United States</Country>
</Customer>
<Customer Id = "2">
<Name>Mudassar Khan</Name>
<Country>India</Country>
</Customer>
<Customer Id ="3">
<Name>Suzanne Mathews</Name>
<Country>France</Country>
</Customer>
<Customer Id ="4">
<Name>Robert Schidner</Name>
<Country>Russia</Country>
</Customer>
</q:Customers>
내 저장 프로 시저 :
ALTER PROCEDURE [dbo].[InsertXML]
@xml XML
AS
BEGIN
;WITH XMLNAMESPACES ('http://quakeml.org/xmlns/quakeml/1.2' as q)
INSERT INTO CustomerDetails
SELECT
Customer.value('@Id','INT') AS CustomerId, --ATTRIBUTE
Customer.value('(Name/text())[1]','VARCHAR(100)') AS Names, --TAG
Customer.value('(Country/text())[1]','VARCHAR(100)') AS Country --TAG
FROM
@xml.nodes('//q:Customers/Customer') as TEMPTABLE(Customer)
END
asp.net의 내 vb.net 코드
Imports System.IO
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Partial Class UploadXml
Inherits System.Web.UI.Page
Protected Sub UploadXML(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_upload.Click
Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim filePath As String = Server.MapPath("~/Uploads/") & fileName
FileUpload1.SaveAs(filePath)
Dim xml As String = File.ReadAllText(filePath)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("InsertXML")
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@xml", xml)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Sub
End Class
고객은 기본 네임 스페이스에 속합니다 http://quakeml.org/xmlns/bed/1.2
.
이 시도:
WITH XMLNAMESPACES ('http://quakeml.org/xmlns/quakeml/1.2' as q,
default 'http://quakeml.org/xmlns/bed/1.2')
SELECT
Customer.value('@Id','INT') AS CustomerId, --ATTRIBUTE
Customer.value('(Name/text())[1]','VARCHAR(100)') AS Names, --TAG
Customer.value('(Country/text())[1]','VARCHAR(100)') AS Country --TAG
FROM
@xml.nodes('/q:Customers/Customer') as TEMPTABLE(Customer);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다