存取图片(C#+Winform+SQL Server)

01月 24th, 2005 by Genthelvite

将picture中的图片保存到数据库中,以及从数据库中的图片读取到picture中!

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();


分享家:Addthis中文版

1 Response to “存取图片(C#+Winform+SQL Server)”

Feed for this Entry
  1. 1

    Frederick G. (Rick) Bridging Says

    Very good informations and give me good few ideas how I can improve my online tool. Why is it twice as easy to train Iraqi fighter pilots? You only have to teach them to take off