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


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

       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>");
        }
  • 相关阅读:
    POJ3246
    .NetCore Docker一次记录
    asp.net利用SmtpClient发送邮件
    Assert类的静态方法
    ado.net 连接数据库
    虚拟目录
    web.config配置详细说明
    图片上传
    .NET操作Excel
    asp.net 数据绑定 -- 时间格式
  • 原文地址:https://www.cnblogs.com/zhangyonglvdaomei/p/3721529.html
Copyright © 2020-2023  润新知