Good Afternoon.
I am workin on online shopping project.
My productDetails.aspx code is like :
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
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.