Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Afternoon.
I am workin on online shopping project.
My productDetails.aspx code is like :
C#
protected void Button1_Click(object sender, EventArgs e)
  {

      SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress;initial catalog=pankshi;integrated security=true");

      SqlCommand cmd = new SqlCommand("insert into tbl_addtocart" + "(productcode,bname,imgpath,cost,qty,totcost)" + "values" + "(@productcode,@bname,@imgpath,@cost,1,@totcost)",con);
      cmd.Parameters.Add(new SqlParameter("@productcode",Labelproductcode .Text ));
      cmd.Parameters.Add(new SqlParameter("@bname", Labelbrandname.Text));
      cmd.Parameters.Add(new SqlParameter("@imgpath", "~/Handler.ashx?Pid=" + ImageId));
      cmd.Parameters.Add(new SqlParameter("@cost", Labelcost.Text));
      cmd.Parameters.Add(new SqlParameter("@totcost", Labelcost.Text));
      try
      {
          con.Open();
          cmd.ExecuteNonQuery();
          con.Close();
          Response.Redirect("addtocart.aspx");
      }
      catch (SqlException ex)
      {

          string errorMessage = "Error in registering user";

          errorMessage += ex.Message;

          throw new Exception(errorMessage);



      }

      finally
      {

          con.Close();

      }
  }

but my imagespath not saved as usual.therefpre my image are not shown in my addtocart.aspx page.

My addtocart.aspx is like
C#
protected void Page_Load(object sender, EventArgs e)
   {
       SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=pankshi;integrated security=True;");
       con.Open();
       sql = "select * from tbl_addtocart";
       ds = new DataSet();
       da = new SqlDataAdapter(sql,con);
       da.Fill(ds,"tbl_addtocart");
       GridView1.DataSource = ds;
       GridView1.DataBind();
   }

please give me right soluton.
Posted
Updated 16-Aug-12 2:07am
v2
Comments
anjani123 16-Aug-12 7:16am    
First check the Handler.ashx file to retrive image.
veenusethi 16-Aug-12 7:33am    
ya you should check the path of image
kk2014 16-Aug-12 7:45am    
where are you saving image? i can't find it...or try something like this. please check your path where you are saving your image. if it is wrong then also you can't save image. try .ashx extension to save image. let me know if you have any query.
AmitGajjar 16-Aug-12 8:16am    
First, you have not provided your code of uploading your image. Secondly, Try to figureout by debugging your application. it is really worth to try for 1 hr for solution rather then posting question in CP.
Sandip.Nascar 21-Aug-12 9:11am    
check whether handle.ashx file is getting the image. Moreover, have a look whether the image is physically stored in the drive.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900