对于我的应用程序,我尝试在 SQLite 应用程序中存储字节数组,我以这种方式填充 SQLite 数据库:
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,Data 是字节数组。其输出结果是一个包含 System.Byte[] 的字段 Data,我不能只显示该字段中的真实字节数组而不显示字符串吗?我到处都使用 Byte[] 类型来填充数据库,因此我不会将其转换为字符串。我希望在数据字段中看到类似这样的内容:01,54,32,23,11,02,53。数据库中数据字段的数据类型是:BLOB。
谁能帮助我实现这一目标?
您应该在语句中使用参数:
string SQL = "INSERT INTO ClockMessages (InsertDateTime, SendDateTime, Data) VALUES (@InsertDateTime, NULL, @Data)";
其他一切似乎都是正确的。
你现在拥有的,称为ToString()
方法上insertdatetime
and data
并将结果连接到 sql 语句。实际上您没有在语句中使用任何参数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)