use*_*900 2 vb.net xml-literals
我正在使用CDATA将所有多行SQL字符串“按原样”存储(感谢一些stackoverflow旧答案),如下所示:
Dim cmd As String = <![CDATA[
INSERT INTO devices
VALUES (
NULL ,
'ONE',
'TWO',
(
SELECT manufacturer_id FROM manufacturers WHERE manufacturer_name = "Bloom"
)
)
]]>.Value()
Run Code Online (Sandbox Code Playgroud)
问题是我需要使用VB变量来解决这个问题。还有另一种方法来代替多个CDATA吗?
<![CDATA[ ...... ]]>.Value() + myVBvar + <![CDATA[ ...... ]]>.Value()
Run Code Online (Sandbox Code Playgroud)
尝试使用SqlParameters
Dim commandString As String = <![CDATA[
INSERT INTO blah VALUES (@One, @Two, @Three, @n)
]]>,Value()
Using command As SqlCommand = new SqlCommand(commandString, connection)
command.Parameters.AddWithValue("@One", valueOne)
command.Parameters.AddWithValue("@Two", valueTwo) ' etc...
' command.execute
End Using
Run Code Online (Sandbox Code Playgroud)