用C#编写winform 存储图片到sql数据库上的代码是怎么样的 怎么在查询的时候给显示在pictruebox上啊
请各位大哥帮忙解决下啊
请各位大哥帮忙解决下啊
解决方案 »
- SQL数据输入,但是没有更新到库中
- 点击鼠标会激发几个事件,讲解有关先后激发顺序的教材哪里有
- .NET中防盗链的操作
- 如何将数据库中的数据传送到pdf中
- 在DataGrid中动态的增加行!
- HttpWebRequest.GetResponse的问题。远程服务器返回错误: (407) 需要代理身份验证。
- 如何能够获取到主板的芯片组型号和内存插槽信息
- 哪位大侠有C# 的电子书。我的油箱是:[email protected] 谢谢
- installshield制作安装程序问题
- 在使用SQLiteDataAdapter的Update时, 不能开启事物
- DOS指令大全、本人最近、急用、、
- axMSComm头疼的问题比较纠结的,大侠们能帮我解决下?
byte[] picbyte;
OpenFileDialog ofdSelectPic = new OpenFileDialog();
if (ofdSelectPic.ShowDialog() == DialogResult.OK)
{
if ((ms = ofdSelectPic.OpenFile()) != null)
{
picbyte = new byte[ms.Length];
ms.Position = 0;
ms.Read(picbyte, 0, Convert.ToInt32(ms.Length));
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ""; sql = "Insert into Person(Photo) values(@Image)";
SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add("@Image", SqlDbType.VarBinary);
cmd.Parameters["@Image"].Value = picbyte; conn.Open();
cmd.ExecuteNonQuery();
conn.Close(); ms.Close();
}
} SqlConnection conn=new SqlConnection();
conn.ConnectionString="";
string strSql="";
SqlCommand cmd=new SqlCommand(strSql,conn);
conn.Open();
SqlDataReader reader=cmd.ExecuteReader();
reader.Read();
MemoryStream ms=new MemoryStream((byte[])reader["Photo"]);
Image image=Image.FromStream(ms,true);
reader.Close();
conn.Close();
picturebox1.Image=image;
FileStream mystream=new FileStream("D:\\A.jpg",FileMode.Open,FileAccess.Read);
long len=mystream.Length;
mycmd.Parameters.Add("@image",SqlDbType.Image,(int)len,"picture");
mycmd.Parameters["@image"].Direction=System.Data.ParameterDirection.Input;
byte []box=new byte[len];
mystream.Read(box,0,(int)len);
mycmd.Parameters["@image"].Value=box;
这里面的路径是什么用的啊 请教
private void btnUpload_Click(object sender, EventArgs e)
{
openPic.Title = "Choose Picture";
openPic.Filter = "JPEG(*.jpg)|*.jpg|PNG(*.png)|*.png"; if (openPic.ShowDialog() == DialogResult.OK)
{
if (File.Exists(openPic.FileName))
{
if (openPic.OpenFile().Length > 1024 * 1024 * 2)
{
MessageBox.Show("图片不得超过2M");
return;
}
string image = openPic.FileName;
string picpath = openPic.FileName;
Guid guid = Guid.NewGuid();
this.txtPhoto.Text = openPic.FileName;
if (!Directory.Exists(Application.StartupPath + "\\image"))
{
Directory.CreateDirectory(Application.StartupPath + "\\image");
}
this.txtPhoto.Tag = Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg";
File.Copy(openPic.FileName, Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg");
picPhoto.Image = Image.FromFile(Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg");
picPhoto.ImageLocation = Application.StartupPath + "\\image\\" + guid.ToString() + ".jpg";
}
else
{
MessageBox.Show("图片不能为空");
return;
}
}
}
能否解释下那个路径是什么意思