码迷,mamicode.com
首页 > 数据库 > 详细

数据库添加图片路径异常

时间:2016-03-15 19:14:36      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

工具:SQLServer2012    Visual Studio 2013

情况:在pictureBox控件中添加照片 然后在保存在数据库中 

        我这样写的技术分享

        出现错误是:

技术分享

  ps:(数据库中有image的类型,因存放的照片要是太多的话,会增加数据库的负担,因此保存图片的路径)

解决办法:

原因:是因为pictureBox1.Imagelocation是null 的

      修改代码:

if (pictureBox1.Image != null)
{
if (pictureBox1.ImageLocation == null)
{
paras.Add(new SqlParameter("@照片", DBNull.Value));
}

else {
paras.Add(new SqlParameter("@照片",pictureBox1.ImageLocation));
}
}
else
{
MessageBox.Show("照片不能为空","提示");
}

 同时还应该将所选文件的路径保存下来

   

this.pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox1.ImageLocation = @openFileDialog1.FileName;//注意要有@ 

结果:

技术分享

 

技术分享

数据库添加图片路径异常

标签:

原文地址:http://www.cnblogs.com/2714585551summer/p/5280597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!