嘿,我正在传输XML文件的内容以进行访问。现在一切正常,但是当我尝试将数据从每个节点的“ desc”部分传输到访问表中的“ desc”列时,我收到此错误(传输卡的所有其他方面都起作用。):{{3} }
我的XML文件如下https://i.stack.imgur.com/4eFTz.png
您知道解决此问题的任何方法吗?另外我还必须避免使用参数,因为我尝试使用它们,因为它只会获取第一个节点的内容(不会循环),因此这就是我避免使用它的原因。这是我的代码:
Dim conn As New OleDbConnection
conn = New OleDbConnection
dbprovider = "Provider=Microsoft.ACE.OLEDB.12.0;"
Dim databasePath = "Data Source = FULL YUGIOH ACCESS DATABASE.accdb;"
conn.ConnectionString = dbprovider & databasePath
Dim ds As New DataSet
Dim command As OleDbCommand
ds.ReadXml("C:\Users\1964\Documents\Visual Studio 2015\Projects\YGO Access Test v10\bin\Debug\MyData.xml")
Dim xmlRoot As XElement = XDocument.Load("C:\Users\1964\Documents\Visual Studio 2015\Projects\YGO Access Test v10\bin\Debug\MyData.xml").Root
Try
conn.Open()
command = New OleDbCommand()
Dim cardname As String
Dim cardtype As String
Dim carddesc As String
Dim cardrace As String
Dim cardimage_url As String
Dim cardatk As Integer
Dim carddef As Integer
Dim cardlevel As Integer
For Each cards As XElement In xmlRoot.<cards>
cardname = cards.<name>.Value
cardtype = cards.<type>.Value
carddesc = cards.<desc>.Value
cardrace = cards.<race>.Value
cardimage_url = cards.<image_url>.Value
cardatk = cards.<atk>.Value
carddef = cards.<def>.Value
cardlevel = cards.<level>.Value
command.Connection = conn
command.CommandText = "insert into hello ([name], [type], [desc], [race], [image_url], [atk], [def], [level]) values('" & cardname & "','" & cardtype & "','" & carddesc & "','" & cardrace & "','" & cardimage_url & "','" & cardatk & "','" & carddef & "','" & cardlevel & "')"
command.ExecuteNonQuery()
Next`
答案 0 :(得分:0)
对于长期解决方案,肯是对的,请使用参数。
要立即解决,请使用双引号 :
Dim text As String
Dim sql As String
Dim quote As String =""""
text = "You have embedded quotes in your text around " + quote + "Gladiator Beast" + quote + "."
sql = text.Replace(quote, quote + quote)
Console.WriteLine(text)
Console.WriteLine(sql)
输出:
You have embedded quotes in your text around "Gladiator Beast".
You have embedded quotes in your text around ""Gladiator Beast"".