如何根据从数据库中读出图片存储的路径,把该图片显示到picturebox中? Me.PictureBox1.Image = Image.FromFile() 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Me.PictureBox1.Image =数据库中读取得路径 你为什么不直接把图片存放数据库private void button1_Click(object sender, System.EventArgs e) { FileStream fs = new FileStream("遗迹.jpg",FileMode.Open,FileAccess.Read); byte[] bytes = new byte[fs.Length]; fs.Read(bytes,0,(int)fs.Length); string sql = "insert TestFiles(MyFileName,FileType,MyFile)values(@FN,@FT,@MF)"; SqlCommand com = new SqlCommand(sql,this.sqlCon); SqlParameter FN = new SqlParameter("@FN",SqlDbType.VarChar); FN.Value = "遗迹"; com.Parameters.Add(FN); SqlParameter FT = new SqlParameter("@FT",SqlDbType.VarChar); FT.Value = "JPG"; com.Parameters.Add(FT); SqlParameter MF = new SqlParameter("@MF",SqlDbType.Image); MF.Value = bytes; com.Parameters.Add(MF); com.CommandType = CommandType.Text; sqlCon.ConnectionString = this.conStr; try { sqlCon.Open(); com.ExecuteNonQuery(); sqlCon.Close(); MessageBox.Show("存入成功!"); } catch(Exception ex) { throw ex; } finally { sqlCon.Close(); } } private void button2_Click(object sender, System.EventArgs e) { string sql = "select MyFile from TestFiles where id = 1"; sqlCon.ConnectionString = this.conStr; SqlCommand readComm = new SqlCommand(sql,this.sqlCon); SqlDataReader dr = null; FileStream fs = null; BinaryWriter bw = null; int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retval; long startIndex = 0; try { sqlCon.Open(); dr = readComm.ExecuteReader(); while(dr.Read()) { fs = new FileStream("TakeOut.jpg",FileMode.OpenOrCreate,FileAccess.Write); bw = new BinaryWriter(fs); retval = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize); while (retval == bufferSize) { bw.Write(outbyte); bw.Flush(); startIndex += bufferSize; retval = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize); } // Write the remaining buffer. bw.Write(outbyte, 0, (int)retval - 1); bw.Flush(); // Close the output file. bw.Close(); fs.Close(); Image im = Image.FromFile("TakeOut.jpg"); this.pictureBox1.Image = im; } sqlCon.Close(); } catch(Exception ex) { throw ex; } finally { sqlCon.Close(); bw.Close(); fs.Close(); } } pictureBox1.Image = Image.FromFile(your image path string) 一句C#代码,求解释 c# 调用 vc 的函数不正常 请教:如何统计由UNION合并后的表 我想让C++写的DLL能直接被C#程序引用,为什么会报LNK2028错 怎样查看本机的端口信息(c#) 请朋友们帮忙解决 “+/– m x 2e”和“+/– m x 10e”代表什么意思?有什么区别? 请高手指点 【高手请进】用c#如何构造一个Collection类,实现Tables似的类? 请教各位大虾 一个简单的问题 有关用C#控制FLASH的显示问题,查了92条帖子,没有我想要的,只好再问了,谢谢先
private void button1_Click(object sender, System.EventArgs e)
{
FileStream fs = new FileStream("遗迹.jpg",FileMode.Open,FileAccess.Read);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes,0,(int)fs.Length);
string sql = "insert TestFiles(MyFileName,FileType,MyFile)values(@FN,@FT,@MF)";
SqlCommand com = new SqlCommand(sql,this.sqlCon);
SqlParameter FN = new SqlParameter("@FN",SqlDbType.VarChar);
FN.Value = "遗迹";
com.Parameters.Add(FN);
SqlParameter FT = new SqlParameter("@FT",SqlDbType.VarChar);
FT.Value = "JPG";
com.Parameters.Add(FT);
SqlParameter MF = new SqlParameter("@MF",SqlDbType.Image);
MF.Value = bytes;
com.Parameters.Add(MF);
com.CommandType = CommandType.Text;
sqlCon.ConnectionString = this.conStr;
try
{
sqlCon.Open();
com.ExecuteNonQuery();
sqlCon.Close();
MessageBox.Show("存入成功!");
}
catch(Exception ex)
{
throw ex;
}
finally
{
sqlCon.Close();
}
} private void button2_Click(object sender, System.EventArgs e)
{
string sql = "select MyFile from TestFiles where id = 1";
sqlCon.ConnectionString = this.conStr; SqlCommand readComm = new SqlCommand(sql,this.sqlCon); SqlDataReader dr = null; FileStream fs = null; BinaryWriter bw = null; int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retval; long startIndex = 0;
try
{
sqlCon.Open();
dr = readComm.ExecuteReader();
while(dr.Read())
{
fs = new FileStream("TakeOut.jpg",FileMode.OpenOrCreate,FileAccess.Write); bw = new BinaryWriter(fs); retval = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize);
while (retval == bufferSize)
{
bw.Write(outbyte);
bw.Flush();
startIndex += bufferSize;
retval = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize);
} // Write the remaining buffer.
bw.Write(outbyte, 0, (int)retval - 1);
bw.Flush(); // Close the output file.
bw.Close();
fs.Close();
Image im = Image.FromFile("TakeOut.jpg"); this.pictureBox1.Image = im;
}
sqlCon.Close();
}
catch(Exception ex)
{
throw ex;
}
finally
{
sqlCon.Close();
bw.Close();
fs.Close();
}
}