Based on the PageLoad and Button1_Click methods, possible places for this error:
1. The way you had coded here -
LOGICAL mistake:
if (cmd != null) { cmd.Dispose(); }
cmd.CommandText = "INSERT INTO cart (ProductID,CustomerName, ProductName, " +
"ProductImage, ProductPrice) VALUES ('" + ProductID + "','" + yourname.Text.ToString() +
"','" + ProductName + "','" +
ProductImageUrl + "','" + Price + "')";
If there is a command
cmd, you go ahead and
'Dispose' it. After that
you continue your execution. Every time you create command you dispose it and then try to access the same 'cmd' for Sql execution.
You should use, try-catch-finally for such sql commands and transactions. In finally check for the cmd value to dispose it.
2. This is based on the hardcoded strings used -
TYPO mistake, if any of them are not existing then you get an error at runtime:
double Price = double.Parse(((Label)DataList1.Controls[0].FindControl("PriceLabel")).Text);
string ProductName = ((Label)DataList1.Controls[0].FindControl("NameLabel")).Text;
string ProductImageUrl = ((Label)DataList1.Controls[0].FindControl("ImageUrlLabel")).Text;
string ProductID = ((HiddenField)DataList1.Controls[0].FindControl("HiddenField1")).ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["techdata"].ToString());