i have problem, when count the quantity column value where its email, the email i got from session["email"], before i do try and catch there error at int count = (int)cmd.ExecuteScalar();, this their error message "Incorrect syntax near '='. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception". i need to count number of quantity from my table. data type for menu_quantity is float.
protected void Page_Load(object sender, EventArgs e)
{
if (Session["email"] != null)
{
A();
//lbltotalitemcart.Text = A().ToString();
}
else
{
lbltotalitemcart.Text = "login email first";
}
}
public int A()
{
String email = Request.QueryString["email"];
string stmt = "SELECT COUNT(menu_quantity) FROM cart Where email=" + email + "";
try
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.
ConnectionStrings["connectionString"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand(stmt, con))
{
con.Open();
int count = (int)cmd.ExecuteScalar();
return count;
}
}
}
catch (Exception e)
{
lbltotalitemcart.Text = e.ToString();
return 0;
}
}