使用BLOB存储字节数组中的SQLite [英] Store Byte array in SQLite using Blob

查看:1745
本文介绍了使用BLOB存储字节数组中的SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的应用我想存储在我的SQLite的应用程序的字节数组,我填我的SQLite数据库是这样的:

For my application I'm trying to store a byte array in my SQLite application, I'm filling my SQLite database this way:

public bool InsertMessage()
    {
        //create string SQl and fill it with the SQLite query for inserting a message.
        string SQL = "Insert into ClockMessages(InsertDateTime, SendDateTime, Data) Values('"+ insertdatetime + "', null, '" + data + "');";
        List<SQLiteParameter> pars = new List<SQLiteParameter>();
        pars.Add(new SQLiteParameter("InsertDateTime", insertdatetime));
        pars.Add(new SQLiteParameter("Data", data));
        //send the SQl query and it's parameters to the SQLiteDatabase class
        return SQLiteDatabase.ExecuteNonQuery(SQL, pars);
    }



在哪里InsertDateTime是DateTime.UtcNow和数据是一个字节数组。这样做的结果输出中包含场数据:System.Byte [],我不能只是显示在这个领域真正的字节数组,而不显示字符串?我'用字节]输入到处填充数据库,所以我不把它转换为字符串。我希望看到这样的事情在数据字段:01,54,32,23,11,02,53在数据库中的数据字段的数据类型为:BLOB

Where InsertDateTime is the DateTime.UtcNow and Data is a byte array. The output of this results in a field Data that contains: System.Byte[], Can't I just show the real byte array in that field, without showing a string? I'am using the Byte[] type everywhere to fill the Database, so I don't convert it to a string. I would like to see something like this in the Data field: 01, 54, 32, 23, 11, 02, 53. The DataType of the Data field in the database is: BLOB.

谁能帮我实现这个

推荐答案

您应该使用语句的参数:

You should use parameters in the statement:

string SQL = "INSERT INTO ClockMessages (InsertDateTime, SendDateTime, Data) VALUES (@InsertDateTime, NULL, @Data)";



其他的一切似乎是正确的。

Everything else seems correct.

什么你现在有,调用的ToString() insertdatetime 方法和数据和并置的结果的SQL语句。其实你没有使用在声明中的任何参数。

What you have now, calls the ToString() method on insertdatetime and data and concatenates the result to the sql statement. Actually you are not using any parameter in the statement.

这篇关于使用BLOB存储字节数组中的SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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