在下面的代码中,我正在尝试验证文本框(txt_quantity 和 txt_discount)
但是MessageBox.Show("Cannot be empty");
我没有得到这个,而是得到了错误
('输入字符串的格式不正确。')
我在这里忘记了什么吗?
txt_数量(整数)
txt_discount(十进制)
decimal Discount, DiscountTotal, Discountgiven, Total;
int Cost, Quantity, ID;
byte[] data;
public void Imagedisplay()
{
using (var con = SQLConnection.GetConnection())
{
using (var selects = new SqlCommand("Select * from employee_product where Codeitem =@Codeitem ", con))
{
selects.Parameters.Add("@Codeitem", SqlDbType.VarChar).Value = _view.txt_code.Text;
using (var reader = selects.ExecuteReader())
{
while (reader.Read())
{
data = (byte[])reader["Image"];
Cost = Convert.ToInt32(reader["Unitcost"]);
Convert.ToInt32(DiscountTotal);
// This is where i'm getting the error at
Quantity = Convert.ToInt32(txt_quantity.Text);
Discount = Convert.ToDecimal(txt_discount.Text); //
Discountgiven = Cost * (Discount / Convert.ToDecimal(100));
DiscountTotal = Cost - Discountgiven;
Total = DiscountTotal * Quantity;
}
}
}
}
}
private void btn_ok_Click(object sender, EventArgs e)
{
Imagedisplay();
using (var con = SQLConnection.GetConnection())
{
if (string.IsNullOrEmpty(txt_quantity.Text) || string.IsNullOrEmpty(txt_discount.Text))
{
MessageBox.Show("Cannot be empty");
}
else
{
{
command.Parameters.Add("@Date", SqlDbType.VarChar).Value = date;
command.Parameters.Add("@Image", SqlDbType.VarBinary).Value = data;
command.ExecuteNonQuery();
Totals();
}
}
}
}
一只萌萌小番薯
相关分类