把图片读到picturebox,再写入数据库
sqlconnection conn=new sqlconnection(@"data source=chenyuming2004/vsdotnet;uid=sa;pwd=cym;database=lhf");
conn.open();
sqlcommand cmd=new sqlcommand("insert into fuser values ('1a','1b',@i)",conn);
byte[] ib=new byte[60000];
filestream fs=new filestream(@"d:/windows temp/temp/1.jpg",filemode.open ,fileaccess.read );
fs.read(ib,0,60000);
cmd.parameters.add("@i",sqldbtype.image,(int)fs.length);
cmd.parameters["@i"].value=ib;
cmd.executenonquery();
conn.close();
-------------------------------------------------------
从数据库读图片到picturebox
sqlconnection conn=new sqlconnection(@"data source=chenyuming2004/vsdotnet;uid=sa;pwd=cym;database=lhf");
conn.open();
sqlcommand cmd=new sqlcommand("select 照片 from fuser where password='1b'",conn);
sqldatareader reader=cmd.executereader();
reader.read();
memorystream buf=new memorystream((byte[])reader[0]);
image image=image.fromstream(buf,true);
picturebox1.image=image;
新闻热点
疑难解答