如何删除图像表格数据库 [英] how to delete image form database

查看:108
本文介绍了如何删除图像表格数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个社交门户网站,用户可以在其中上传图像,这些图像名称存储在数据库表中,图像存储在文件夹图片中

我想如何允许用户从数据库中删除其图像

i have the social portal in which user upload images these images name are stored in database table and images are stored in Folder Pictures

i want how to alow user to delete their images form database

protected void Button2_Click(object sender, EventArgs e)
  {
      if (!object.Equals(Session["Id"], null))
      {
          if (Object.Equals(Session["Id"], Request.QueryString["Id"].ToString()))
          {
              if (FileUpload2.PostedFile != null)
              {
                  string myMap = MapPath("~/").ToLower();
                  Random r = new Random();
                  int next = r.Next();
                  string ImageName = FileUpload2.PostedFile.FileName;
                  sImageFileExtension = ImageName.Substring(ImageName.LastIndexOf(".")).ToLower();
                  if (sImageFileExtension == ".gif" || sImageFileExtension == ".png" || sImageFileExtension == ".jpg" || sImageFileExtension == ".jpeg" || sImageFileExtension == ".bmp")
                  {
                      string ImageSaveURL = myMap + "Pictures/" + next + sImageFileExtension;



                      FileUpload2.PostedFile.SaveAs(ImageSaveURL);

                      //  Session["Id"]=dt.Rows[0]["Id"].ToString();
                      string RegisterQuery = "Insert Into Pic(Id,Image) Values('" + Session["Id"].ToString() + "','" + next + sImageFileExtension + "')";

                      dbClass.ConnectDataBaseToInsert(RegisterQuery);
                      Response.Redirect("UserDetails.aspx?Id=" + Request.QueryString["Id"].ToString());


                  }

              }
          }
          else
          {

          }
      }


这是上面的代码,用于将图像存储在数据库中




我如何允许用户删除他/她想要的图像


this is above code to store images in database




how i allow the user to delte the images to which he/she want

推荐答案

首先允许用户选择要删除的文件.

然后,您需要做两件事-
1)使用删除查询从数据库中删除图像名称.
2)从文件夹中删除实际的图像.
First allow the user to choose the file to delete.

Then, you need to do two things -
1) Remove the image name from the database by using a delete query.
2) Remove the actual image from the folder.


尝试尝试此链接,您将获得解决方案....

如何动态为自动增量添加值字段? [
try try this link u ll got a solution....

How can i dynamically add value to the auto increment field?[^]


这篇关于如何删除图像表格数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆