【发布时间】:2014-09-14 19:00:23
【问题描述】:
我目前正在做一个关于购物车的项目。我已经完成了购物车,但不知何故我无法计算购物车并且它一直显示为 0。 我已经检查了用户的会话是否已被抓取。
这是我使用的方法:
//check cart count
public int getCartCount(string Username)
{
MySql.Data.MySqlClient.MySqlConnection msqlConnection = null;
msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;User Id=root;password=rootPassw0rd;Persist Security Info=False;database=infosec;Integrated Security=False");
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
//define the connection used by the command object
msqlCommand.Connection = msqlConnection;
msqlCommand.CommandText = "SELECT COUNT(*) FROM shoppingcart WHERE Item_Id = @Username ";
msqlCommand.Parameters.AddWithValue("@Username", _Username);
msqlConnection.Open();
string nofRow = "";
MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();
if (msqlReader.Read())
{
nofRow = msqlReader["COUNT(*)"].ToString();
}
msqlConnection.Close();
msqlConnection.Close();
msqlReader.Dispose();
int cart = Convert.ToInt32(nofRow);
return cart;
这是 .axps 页面的代码:
//cart increase if there items added.
if (Session["customer_Username"] == null)
{
cartCount.InnerText = "Cart (0)";
}
else
{
cartBLL cBLL = new cartBLL();
string a = Session["customer_Username"].ToString();
int count = cBLL.getCartCount(a);
cartCount.InnerText = "Cart (" + count + ")";
}
希望大家能帮我找出问题。 提前致谢。
【问题讨论】:
标签: c# mysql asp.net shopping-cart