再次回来。这是我的代码。错误是,在使用表单向数据库添加数据时,组合框让我失望。
有谁可以帮我离开这里吗。问题在于这一行“com.Parameters.AddWithValue("@ProductCategory", cmbProductCategory.SelectedItem.ToString());"
SqlCeCommand com = new SqlCeCommand("INSERT INTO Products_Master(ProductCode, ProductName, ProductDescription, ProductCategory, LandingPrice, SellingPrice, Stock) VALUES(@ProductCode, @ProductName, @ProductDescription, @ProductCategory, @LandingPrice, @SellingPrice, @Stock)", con);
com.Parameters.AddWithValue("@ProductCode", txtProductCode.Text);
com.Parameters.AddWithValue("@ProductName", txtProductName.Text);
com.Parameters.AddWithValue("@ProductDescription", txtProductDescription.Text);
com.Parameters.AddWithValue("@ProductCategory", cmbProductCategory.SelectedItem.ToString());
com.Parameters.AddWithValue("@LandingPrice", txtLandingPrice.Text);
com.Parameters.AddWithValue("@SellingPrice", txtSellingPrice.Text);
com.Parameters.AddWithValue("@Stock", txtStock.Text);
try
{
int affectedRows = com.ExecuteNonQuery();
if (affectedRows > 0)
{
System.Windows.Forms.MessageBox.Show("Insert Success !", System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCategoryName.Text = "";
Category_Master_Changed();
}