在sql compact中保存图像 [英] save image in sql compact
本文介绍了在sql compact中保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
即时创建Windows移动应用程序我想在sqlcompact中保存图像,这是我的代码
hi everyone
im creating windows mobile application i want to save image in sqlcompact and this is my code
OpenFileDialog fd = new OpenFileDialog();
fd.Filter="jpg file (*.jpg)|*.jpg";
if (fd.ShowDialog() == DialogResult.OK)
{
string sd = fd.FileName.ToString();
pictureBox1.Image = sd;
}
i知道当我使用Windows应用程序时我使用
i know when i use windows application i use
string sim=opf.filename.tostring();
pictureBox.imagelocation= sim
,,,,,它工作正常
但是对于移动应用程序我们没有imagelocation优点
所以任何建议都将受到赞赏....
,,,,,it work fine
but with mobile application we don't have imagelocation propriety
so any suggestion will be appreciated ....
推荐答案
使用System.Data.SqlServerCe;
private void updatedata()
{
尝试
{
if(imagename!=)
{
FileStream fs;
byte [] picbyte;
using(fs = new FileStream(@imagename, FileMode.Open,FileAccess.Read))
{
//读取图像的字节数组
picbyte = new byte [fs。长度];
fs.Read(picbyte,0,System.Convert.ToInt32(fs.Length));
}
string connstr = @Data Source = .\TestImage.sdf; Persist Security Info = False;
string query = 插入test_table(id_image,pic)+
值(@ id,@ pic);
使用(SqlCeConnection conn = new SqlCeConnection(connstr))
using(SqlCeCommand cmd = new SqlCeCommand(query,conn))
{
conn.Open();
SqlCeParameter picparameter = new SqlCeParameter();
picparameter.SqlDbType = SqlDbType.Image;
picparameter.ParameterName =pic;
picparameter.Value = picbyte;
cmd.Parameters.Add(picparameter);
SqlCeParameter idparameter = new SqlCeParameter();
idparameter.SqlDbType = SqlDbType.Int;
idparameter.ParameterName =id;
idparameter.Value = textBox1.Text;
cmd.Parameters.Add(idparameter);
cmd.ExecuteNonQuery();
MessageBox.Show(Image Added);
}
}
}
using System.Data.SqlServerCe;
private void updatedata()
{
try
{
if (imagename != "")
{
FileStream fs;
byte[] picbyte;
using(fs = new FileStream(@imagename, FileMode.Open, FileAccess.Read))
{
//a byte array to read the image
picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
}
string connstr = @"Data Source=.\TestImage.sdf;Persist Security Info=False;"
string query = "insert into test_table(id_image,pic) " +
"values(@id, @pic)";
using(SqlCeConnection conn = new SqlCeConnection(connstr))
using(SqlCeCommand cmd = new SqlCeCommand(query, conn))
{
conn.Open();
SqlCeParameter picparameter = new SqlCeParameter();
picparameter.SqlDbType = SqlDbType.Image;
picparameter.ParameterName = "pic";
picparameter.Value = picbyte;
cmd.Parameters.Add(picparameter);
SqlCeParameter idparameter = new SqlCeParameter();
idparameter.SqlDbType = SqlDbType.Int;
idparameter.ParameterName = "id";
idparameter.Value = textBox1.Text;
cmd.Parameters.Add(idparameter);
cmd.ExecuteNonQuery();
MessageBox.Show("Image Added");
}
}
}
这篇关于在sql compact中保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文