Hi,
So far the code you've posted above is fine except the below part.
con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
com = con.CreateCommand();
com.CommandText = "insert into cart select pid,pname,pimg,price from table_name where pid=@pid";
com.Parameters.AddWithValue("@pname",pname);
com.Parameters.AddWithValue("@pimg",pimg);
com.Parameters.AddWithValue("@price",price);
Here the variables like pid, pname, pimg and price are not declared.
You have to either declare them in the start of the method or get the values from user input and assign here.