if (Pic1.Image == null)
{
MessageBox.Show("请选择要保存的图像!");
}
else
{
try
{
string fullpath = op.FileName;
FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] imagebytes = br.ReadBytes((int)fs.Length); SetConnection();
SQLiteCommand com = sql_con.CreateCommand();
sql_con.Open(); com.CommandText = "insert into ImageStore(ImageBlob) values(@image)"; com.Parameters.AddWithValue("@image", imagebytes);
int Flag = 0; Flag += com.ExecuteNonQuery();
sql_con.Close();
if (Flag == 1)
{
MessageBox.Show("图片保存成功!");
Pic1.Image = null;
getMaxValue();
}
else
{
MessageBox.Show("图片保存失败!");
Pic1.Image = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这是插入sqlite数据库图片的代码,请问有谁能看出问题,我执行后总是提示no such table ,我确定数据库和表名是没问题的,字段类型也是blob的
{
MessageBox.Show("请选择要保存的图像!");
}
else
{
try
{
string fullpath = op.FileName;
FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] imagebytes = br.ReadBytes((int)fs.Length); SetConnection();
SQLiteCommand com = sql_con.CreateCommand();
sql_con.Open(); com.CommandText = "insert into ImageStore(ImageBlob) values(@image)"; com.Parameters.AddWithValue("@image", imagebytes);
int Flag = 0; Flag += com.ExecuteNonQuery();
sql_con.Close();
if (Flag == 1)
{
MessageBox.Show("图片保存成功!");
Pic1.Image = null;
getMaxValue();
}
else
{
MessageBox.Show("图片保存失败!");
Pic1.Image = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这是插入sqlite数据库图片的代码,请问有谁能看出问题,我执行后总是提示no such table ,我确定数据库和表名是没问题的,字段类型也是blob的
为什么是+=?你是执行到这句报的错?
String fullPath = @"F:\kankan\04.jpg";
FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] imgbytes = br.ReadBytes((int)fs.Length); using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + path))
{
conn.Open();
SQLiteCommand cmd = new SQLiteCommand(conn);
cmd.CommandText = "insert into ImageStore values (null,@img)";
cmd.Parameters.AddWithValue("@img", imgbytes); int result = cmd.ExecuteNonQuery();
}
这是我写的测试程序,已通过。
所以它会在你打开图片的地方创建一个空数据库,造成错误,http://bbs.csdn.net/topics/250023126
只要设置op.RestoreDirectory = true就可以了