OLE DB对象字段到SQL图像字段迁移c#

时间:2011-06-17 17:13:52

标签: sql ms-access object migration ole

我正在尝试将OLE对象字段(访问2003)迁移到SQL 2005字段,现在我设法让Doc文件正常工作(复制了函数),

但EXCEL / PDF和其他文件没有运气。

        short sFlag = 0;
        int nIndex = 0;
        int nCount = 0;
        int nOffset = 0;
        int nImgLen = 0;
        int nReadbyte = 14400;
        string szImgType = string.Empty;


        if (bData.Length > 0)
        {
            MemoryStream memStream = new MemoryStream(bData, true);
            byte[] bArray = new byte[nReadbyte];
            nCount = memStream.Read(bArray, 0, nReadbyte);
            if (bArray[78] == (byte)0x42 && bArray[79] == (byte)0x4D) //BMP FORMAT
            {
                sFlag = 1;
                nOffset = 78;
                szImgType = "image/bmp";
            }
            else
            {
                for (nIndex = 78; nIndex < nReadbyte - 2; nIndex++)
                {
                    if (bArray[nIndex] == (byte)0xFF && bArray[nIndex + 1] == (byte)0xD8) //JPG FORMAT
                    {
                        sFlag = 2;
                        nOffset = nIndex;
                        szImgType = "image/pjpeg";
                        break;
                    }
                    else if (bArray[nIndex] == (byte)0x25 && bArray[nIndex + 1] == (byte)0x50) //PDF FORMAT
                    {
                        sFlag = 3;
                        nOffset = nIndex;
                        szImgType = "application/pdf";
                        FileType = "application/pdf";
                        break;
                    }
                    else if (bArray[nIndex] == (byte)0xD0 && bArray[nIndex + 1] == (byte)0xCF) //MSWORD FORMAT
                    {
                        sFlag = 4;
                        nOffset = nIndex;
                        szImgType = "application/msword";
                        FileType = "application/msword";
                        break;
                    }


                }
            }
            if (sFlag > 0)
            {
                nImgLen = bData.Length - nOffset;
                memStream.Position = 0;
                memStream.Write(bData, nOffset, nImgLen);
                memStream.Position = 0;
                byte[] bImgData = bData; //new byte[nImgLen];
                return bImgData;
            }
            else
            {
                return null;
            }


        }
        else {
            return null;
        }
    }

想知道将ole对象迁移到SQL 2005字段的任何指针/查找。

-Prash

0 个答案:

没有答案