为什么我的BLOB字段仍然是13B-我做错了什么? [英] Why my BLOB field is still 13B - what I am doing wrong?

查看:86
本文介绍了为什么我的BLOB字段仍然是13B-我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据存储在MySQL BLOB字段中.我正在使用以下代码:

I would like to store the data in the MySQL BLOB field. I am using the following code:

int length = (int)fs.Length;
                        buffer = new byte[length];
                        int count;
                        int sum = 0;
                        while ((count = fs.Read(buffer, sum, length - sum)) > 0)
                            sum += count;

                        prikaz.CommandText = "INSERT INTO attachments (ReferenceID,Filename,File) VALUES ('" + referenceID + "','test','" + buffer + "')";
                        prikaz.ExecuteNonQuery();

但是在数据库中,BLOB字段始终为13B.能否请您指教?谢谢!

But in the database, the BLOB field has always 13B. Could you please advice? Thanks!

推荐答案

您正在使用字符串连接将字节数组转换为字符串.那不会给您想要的数据.每行的blob字段中的数据都是相同的:我怀疑是ASCII字符串"System.Byte []".

You're converting the byte array to a string using string concatenation. That won't give you the data you want. The data in your blob field will be the same for every row: the string "System.Byte[]" in ASCII, I suspect.

始终会对此类事情使用参数化命令,这样您就不必担心转换和转义.

Always use a parameterized command for this sort of thing, so that you don't need to worry about conversions and escaping.

这篇关于为什么我的BLOB字段仍然是13B-我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆