标签:style blog class code java tar
上传图片,将图片名称插入到数据表中
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>"); }
ASP.NET中将图片文件保存到数据库,布布扣,bubuko.com
标签:style blog class code java tar
原文地址:http://www.cnblogs.com/zhangyonglvdaomei/p/3721529.html