具体要求如下:
在窗体中通过打开文件对话框选择计算机磁盘上的一个图片,然后这个图片可以在窗体的Image控件中显示,最后再通过单击一个“确定”按钮后可以把这张图片存入输入库sql server不知哪位高手有这个源码共享一下,谢谢
在窗体中通过打开文件对话框选择计算机磁盘上的一个图片,然后这个图片可以在窗体的Image控件中显示,最后再通过单击一个“确定”按钮后可以把这张图片存入输入库sql server不知哪位高手有这个源码共享一下,谢谢
解决方案 »
- 尼玛,都来看看,哥实现了一个牛逼的功能。。。
- 【请教:比较大的项目,使用了hashtable 现在数据量大了,占用内存非常大,如何解决?】
- 超简单问题,数学略好的请进来
- .net 源码加密软件MaxtoCode Professional 3.03下载
- 还是有关正则表达式的问题
- 做项目时 按照正常流程需要写哪写文档,每个文档的作用是什么,以及面向哪写群体?
- 数据库连接问题
- 代码的合并
- C#(64位系统) 解决"未能加载文件或程序集,或它的某一个依赖项..."
- inetpub\wwwroot\chapter7\Books_with_Parm.xsl(26,15): 错误: 变量或参数“discount”未定义或超出范围。
- 如何在DataGrid中单击一行后打开一个新的窗体,并向窗体中传入一个变量数据
- 字符串验证问题,请教
{
Stream ImageStream;
string Path=File1.PostedFile.FileName;// 文件名称
int Size = File1.PostedFile.ContentLength; // 文件大小
string Type = File1.PostedFile.ContentType; // 文件类型
ImageStream = File1.PostedFile.InputStream;
byte[] Content = new byte[Size];
int Status = ImageStream.Read(Content, 0, Size); // 写入数据库
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand comm=new SqlCommand("insert into testimage (UserName,Image,Path,Type) values(@UserName,@Image,@Path,@Type)",conn); comm.CommandType = CommandType.Text;
comm.Parameters.Add("@UserName", SqlDbType.VarChar, 255).Value = txtUserName.Text;
comm.Parameters.Add("@Image", SqlDbType.Image).Value = Content;
comm.Parameters.Add("@Path", SqlDbType.VarChar, 255).Value = Path;
comm.Parameters.Add("@Type", SqlDbType.VarChar, 255).Value = Type; conn.Open();
comm.ExecuteNonQuery();
conn.Close();
DataBind();
}http://singlepine.cnblogs.com/archive/2005/11/30/288027.html
string txt=this.ofdLoadPhoto.FileName;
FileStream fs=File.OpenRead(txt);
byte[] content=new byte[fs.Length];
fs.Read(content, 0,content.Length);
fs.Close();
string sql ="update xs_ksxx set zp=@pic where xjh='"+this.txtXJH.Text.Trim()+"'";
SqlCommand cmd=new SqlCommand(sql,con);
cmd.CommandType=CommandType.Text;
cmd.Parameters.Add("@pic",SqlDbType.Image).Value=content;
cmd.ExecuteNonQuery();
cmd.Dispose();
byte[] imagebytes=null;
FileStream fs=new FileStream(Image_path,FileMode.Open);
BinaryReader br=new BinaryReader(fs);
imagebytes=br.ReadBytes(br.Length);
SqlParameter parInput22=cmd.Parameters.Add("@员工图片",SqlDbType.Image);
parInput22.Direction=ParameterDirection.Input;
cmd.Parameters["@员工图片"].Value=imagebytes;
cmd.ExecuteNonQuery();
数据库中操作图片
How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
DataGrid显示图片(物理路径式和Stream流式)和添加图片到数据库
http://singlepine.cnblogs.com/articles/288027.html
if(myReader["studentPhoto"].ToString() != "") // 如果图片字段不为空时显示图片数据
{
imagebytes = (byte[]) (myReader["studentPhoto"]);
studentAbout.Text = myReader["studentAbout"].ToString(); // 预先显示一下附注信息,免得数据库图片字段有值,但不是图片时产生异常而不执行下面的内容。
if (imagebytes.Length > 0)
{
MemoryStream stream = new MemoryStream(imagebytes, true); // 创建一个内存流,支持写入,用于存放图片二进制数据
try
{
stream.Write(imagebytes, 0, imagebytes.Length);
Bitmap FinalImage = new Bitmap(stream);
this.studentPhoto.Image = FinalImage;
this.studentPhoto.Refresh();
}
finally
{
stream.Close();
}
}
}
cmd.Parameters.Add("@studentPhoto", SqlDbType.Image).Value = imagebytes;