在sql server varbinary数据类型中插入数据 [英] Insert data in sql server varbinary datatype
本文介绍了在sql server varbinary数据类型中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我跟随表
CREATE TABLE [dbo]。[客户](
[CustomerID] [ int ] IDENTITY ( 1 , 1 ) NOT < span class =code-keyword> NULL ,
[City] [ varchar ]( 50 ) NULL ,
[国家] [ varchar ]( 50 ) NULL ,
[PostalCode] [ nchar ]( 10 ) NULL ,
[图片] [ varbinary ](max)
) ON [ PRIMARY ]
请求se帮我编写查询以在此表中插入数据
提前谢谢
解决方案
请参阅此一: http://www.fishofprey.com/2010/08/inserting- file-data-into-varbinarymax.html [ ^ ]
喜欢这个
CREATE TABLE [dob]。[Customer](
[CustomerID] [int] IDENTITY(1,1)NOT NULL,
[City] [varchar](50)NULL,
[Country] [varchar](50)NULL,
[PostalCode] [nchar](10)NULL,
[图片] [nvarchar]()
)ON [PRIMARY]
INSERT INTO [dbo]。[Customer] - ([City],[Country],[PostalCode],[Picture])
VALUES('Oshkosh','USA','54903 ',0x4F),
('Harlingen','USA','78551',0xCE)
SELECT [CustomerID]
,[City]
,[Country]
,[PostalCode]
,[Picture]
FROM [dbo]。 [客户]
GO
CustomerID城市国家PostalCode图片
~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 Oshkosh USA 54903 0x4F
2 Harlingen USA 78551 0xCE
[edit]
DECLARE @strImage nvarchar(888)
SET @strImage ='c:\users\PT\MyImage.jpg'
DECLARE @strExec [nvarchar](999)
SET @strExec = N'INSERT INTO [dbo]。[Customer](Picture)SELECT * FROM OPENROWSET(BULK N'''+ @strImage +''', SINGLE_BLOB)as [imageDedicated]'
EXEC(@strExec)
[end编辑]
I've following table
CREATE TABLE [dbo].[Customer](
[CustomerID] [int] IDENTITY(1,1) NOT NULL,
[City] [varchar](50) NULL,
[Country] [varchar](50) NULL,
[PostalCode] [nchar](10) NULL,
[Picture] [varbinary](max)
) ON [PRIMARY]
please help me to write query to insert data in this table
Thanks in advance
解决方案
Refer this one: http://www.fishofprey.com/2010/08/inserting-file-data-into-varbinarymax.html[^]
Like this
CREATE TABLE [dob].[Customer]( [CustomerID] [int] IDENTITY(1,1) NOT NULL, [City] [varchar](50) NULL, [Country] [varchar](50) NULL, [PostalCode] [nchar](10) NULL, [Picture] [nvarchar]() ) ON [PRIMARY]
INSERT INTO [dbo].[Customer] --([City], [Country], [PostalCode], [Picture]) VALUES('Oshkosh','USA','54903',0x4F), ('Harlingen','USA','78551',0xCE)
SELECT [CustomerID] ,[City] ,[Country] ,[PostalCode] ,[Picture] FROM [dbo].[Customer] GO
CustomerID City Country PostalCode Picture ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 Oshkosh USA 54903 0x4F 2 Harlingen USA 78551 0xCE
[edit]
DECLARE @strImage nvarchar(888) SET @strImage = 'c:\users\PT\MyImage.jpg'
DECLARE @strExec [nvarchar](999) SET @strExec = N'INSERT INTO [dbo].[Customer](Picture) SELECT * FROM OPENROWSET(BULK N''' + @strImage + ''', SINGLE_BLOB) as [imageDedicated]'
EXEC(@strExec)
[end edit]
这篇关于在sql server varbinary数据类型中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文