ASP.NET中将图片文件保存到数据库

时间:2014-05-12 01:04:51   收藏:0   阅读:293

 

               上传图片,将图片名称插入到数据表中

bubuko.com,布布扣
   protected void btnSend_Click(object sender, EventArgs e)
    {
        string Name = txtName.Text;
        string pictureName = fupPicturePath.FileName;    //获取文件名称(FileUpload ID="fupPicturePath")
        string dateSend = DateTime.Now.ToString();        //获取当前时间
        //获取上传文件的后缀名
        string lastName = pictureName.Substring(pictureName.LastIndexOf(".") + 1);
        if (lastName.ToLower() == "jpg" || lastName.ToLower() == "bmp" || lastName.ToLower() == "gif")
        {
            string SavePath = Server.MapPath("Img/") + pictureName;     //设置保存路径
            fupPicturePath.PostedFile.SaveAs(SavePath);                   //保存上传的图片
            string sqlIns = "insert into tb_pictureSend(Name,pictureName,dateSend) values(‘"
                + Name + "‘,‘" + pictureName + "‘,‘" + dateSend + "‘)";
            SqlConnection con = createCon();
            con.Open();
            SqlCommand com = new SqlCommand(sqlIns, con);
            com.ExecuteNonQuery();
            gvBind();
            con.Close();
        }
        else
            Response.Write("<script>alert(‘图片格式不正确!!‘)</script>");
    }
bubuko.com,布布扣

 

ASP.NET中将图片文件保存到数据库,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!