protected void btnAddtoCart_Click(object sender, EventArgs e)
{
int qty = int.Parse(txtQuantity.Text);
try
{
string connectionStr = ConfigurationManager.ConnectionStrings["AUMSConnectionString"].ConnectionString;
SqlConnection myConnect = new SqlConnection(connectionStr);
string command = "INSERT INTO OrderDetails( ProductID, ProductName, UnitPrice, OrderQuantity, UserName) VALUES(@ProductID, @ProductName, @UnitPrice, @OrderQuantity, @UserName)";
SqlCommand cmd = new SqlCommand(command, myConnect);
cmd.Parameters.AddWithValue("@ProductID", Convert.ToInt16**(ProductID))**;
cmd.Parameters.AddWithValue(" @ProductName", name);
cmd.Parameters.AddWithValue("@UnitPrice", price);
cmd.Parameters.AddWithValue("@OrderQuantity",qty);
cmd.Parameters.AddWithValue("@UserName", Session["UserName"].ToString());
myConnect.Open();
}
catch (Exception ex)
{
}
}
我无法从上一页检索ProductID
,但下面的代码可以使用。
string command = "INSERT INTO OrderDetails(OrderID, OrderBaseID, ProductID, ProductName, UnitPrice, OrderQuantity, AccountID) VALUES(1, 1, "+ Convert.ToInt16(ProductID) + ",'" + name + "','19.00',5,'Lewis')";
谁能告诉我这是什么错误?我试过调试但是返回的值是null。