[英]Store a byte[] stored in a SQL XML parameter to a varbinary(MAX) field in SQL Server 2005. Can it be done?
Store a byte[] stored in a SQL XML parameter to a varbinary(MAX) field in SQL Server 2005. Can it be done ? 将存储在SQL XML参数中的byte []存储到SQL Server 2005中的varbinary(MAX)字段。可以完成吗?
Here's my stored procedure: 这是我的存储过程:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddPerson]
@Data AS XML
AS
INSERT INTO Persons (name,image_binary)
SELECT
rowWals.value('./@Name', 'varchar(64)') AS [Name],
rowWals.value('./@ImageBinary', 'varbinary(MAX)') AS [ImageBinary]
FROM
@Data.nodes ('/Data/Names') as b(rowVals)
SELECT SCOPE_IDENTITY() AS Id
In my schema Name is of type String and ImageBinary is o type byte[]. 在我的架构中,Name的类型为String,而ImageBinary的类型为byte []。 Should I use the String type for ImageBinary too ?
我也应该对ImageBinary使用String类型吗? Would I then need to specially encode that string somehow ?
然后,我是否需要以某种方式对字符串进行特殊编码?
Assuming that you use Base64 for the byte[] in XML, the approach which uses XQuery as described in the following article should work: 假设您对XML中的byte []使用Base64,则下面的文章中介绍的使用XQuery的方法应该可以工作:
http://blogs.msdn.com/sqltips/archive/2008/06/30/converting-from-base64-to-varbinary-and-vice-versa.aspx http://blogs.msdn.com/sqltips/archive/2008/06/30/converting-from-base64-to-varbinary-and-vice-versa.aspx
Probably not. 可能不是。
XML is alphanumeric (eg codes > 32 basically) where byte[] would be 0->255. XML是字母数字(例如,基本上是> 32的代码),其中byte []为0-> 255。
In this case, you have 2 sets of data: a name and a BLOB. 在这种情况下,您有2组数据:名称和BLOB。 So treat them as such, no?
所以这样对待他们,不是吗?
ALTER PROCEDURE [dbo].[AddPerson]
@Name AS varchar(64)
@Data AS varbinary(max)
AS
INSERT INTO Persons (name, image_binary)
VALUES (@Name, @Data)
SELECT SCOPE_IDENTITY() AS Id
GO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.