0

I have a client who is asking me to import jpeg files into their SQL Server database.

The problem is that their database vendor originally build the product in SQL Server 2000 (or earlier) although their database currently sits on a SQL Server 2008 R2 instance. It appears that their old data looks like it's just being dumped into a big field of datatype text.

Is it possible to read the jpeg file into a MemoryStream then write that directly to the SQL Server database? If so, how would I go about doing this? Or, is there a better way?

Thanks,

Andre

4

2 回答 2

1

将图片存储在数据库中既不划算也不高效,最好的方法是存储文件的路径。

于 2013-05-21T01:55:44.363 回答
0

我想如果你真的需要这样做,你可以将字节流构建成这样的字符串:

        MemoryStream ms = [your stream];
        Byte[] memoryBytes = ms.ToArray();
        StringBuilder sBuilder  = new StringBuilder();

        foreach(byte nextByte in memoryBytes)
            sBuilder.Append((char)nextByte);

        string res = sBuilder.ToString();

然后通过传递字符串将其存储在数据库中。您应该尝试通过提供更新他们的数据库结构来从您的客户那里获得一些额外的工作;)

于 2013-05-21T14:21:16.453 回答