您好我想使用C#Compact框架将图像插入数据库SQL CE ..
我的代码
FileInfo Filfo=New FileInfo(OpenFileDialog1.FileName.ToSting());
Long LngLength=5;
FileStream fstrm=new FileStream(OpenFileDialog1.FileName.ToSting());
BinaryReader br=new BinaryReader(Fstrm);
byte[] data=br.ReadBytes(int)lngLenght);
string Query="insert into category(cm_id,cm_image) values(@id,@img)";
sqlcecommand cmd=new sqlcecommand(Query,cls.Connect());
cmd.parameters.add(new sqlcparameter("@id",(object)textbox1.text);
cmd.parameters.add(new sqlcparameter("@id",(object)data);
cmd.executenonquery();
但它显示错误.... openfiledialog1,找不到文件....
我的加载图片代码
openfiledialog open=new opendailog();
open.filter="Image Files(*.jpg*bmp;|*.jpg;*bmp;
if(open.showdilog()==dialogresult.Ok)
{
pitcherbox1.image=new bitmap(open.file);
}
答案 0 :(得分:1)
FileInfo Filfo=New FileInfo(OpenFileDialog1.FileName.ToSting());
Long LngLength=5;
FileStream fstrm=new FileStream(OpenFileDialog1.FileName.ToSting());
BinaryReader br=new BinaryReader(Fstrm);
byte[] data=br.ReadBytes(int)lngLenght);
string Query="insert into category(cm_id,cm_image) values(@id,@img)";
sqlcecommand cmd=new sqlcecommand(Query,cls.Connect());
cmd.parameters.add(new sqlcparameter("@id",(object)textbox1.text);
cmd.parameters.add(new sqlcparameter("@img",(object)data);
cmd.executenonquery();
答案 1 :(得分:0)
从错误消息中看起来过滤器无效。
只试用*.jpg;*.bmp