【问题标题】:How to insert JPEG into a SQL Server 2000 database field of image type using Transact SQL如何使用 Transact SQL 将 JPEG 插入图像类型的 SQL Server 2000 数据库字段
【发布时间】:2010-11-15 21:56:04
【问题描述】:

我试图弄清楚如何使用 Transact SQL 将 .JPG 文件插入到图像类型的 SQL Server 2000 数据库字段中。谢谢。

【问题讨论】:

    标签: tsql image sql-server-2000 insert-update


    【解决方案1】:

    本教程中找到的存储过程对我有用:

    Brief tutorial on text, ntext, and image

    【讨论】:

      【解决方案2】:

      有一个工具叫 textcopy.exe 您可以在 MSSQL\Binn 下找到它或使用 SQL Server 2000 SP4 获取它

      Alexander Chigrik 为使用 SQL 查询编写了一个不错的存储过程:

      http://www.mssqlcity.com/Articles/KnowHow/Textcopy.htm

      【讨论】:

        【解决方案3】:

        使用 OPENROWSET:

        INSERT MyTable (ImageColumnName) 
        SELECT BulkColumn FROM OPENROWSET (BULK 'c:\myjpeg.jpg', SINGLE_BLOB) AS X
        

        已编辑 糟糕,您使用的是 2000 - 不支持以前的解决方案。您必须使用 WRITETEXT:

        CREATE TABLE MyTable 
        (
            ID INT PRIMARY KEY IDENTITY (1,1), 
            ImageColumnName IMAGE NULL
        )
        GO
        
        -- must insert a dummy value into the image column for TEXTPTR 
        -- to work in next bit
        DECLARE @RowId INT
        INSERT MyTable (ImageColumnName) VALUES (0xFFFFFFFF)
        SELECT @RowId = SCOPE_IDENTITY()
        
        -- get a pointer value to the row+column you want to 
        -- write the image to
        DECLARE @Pointer_Value varbinary(16)
        SELECT @Pointer_Value = TEXTPTR(ImageColumnName)
        FROM MyTable
        WHERE Id = @RowId
        
        -- write the image to the row+column pointer
        WRITETEXT MyTable.ImageColumnName @Pointer_Value 'c:\myjpeg.jpg'
        

        【讨论】:

        • 这就是我尝试做的,但我认为这是 sql server 2005 语法,在 2000 年似乎不起作用
        猜你喜欢
        • 2017-12-02
        • 2015-06-08
        • 1970-01-01
        • 2014-03-03
        • 2015-03-12
        • 1970-01-01
        • 2022-01-17
        • 2012-09-05
        • 1970-01-01
        相关资源
        最近更新 更多