嗨,大家好,我正在尝试使用文本框插入布尔值,现在出现一个错误,提示“字符串未被识别为有效的布尔值”。因为我在文本框中添加了0。
以下是我的业务层中用于插入值的方法
public void ADD_CUSTOMER(string Customer_Code, string Customer_Nmae, string Address, string Country, string City, string Phone, string Fax, string Mobile,
string Email, string Note, byte[] Cust_Imaige, decimal Credit, decimal Debit, decimal Balance, bool Statas, string criterion)
{
DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
DAL.open();
SqlParameter[] param = new SqlParameter[16];
param[0] = new SqlParameter("@Customer_Code", SqlDbType.NVarChar, 25);
param[0].Value = Customer_Code;
param[1] = new SqlParameter("@Customer_Nmae", SqlDbType.NVarChar, 100);
param[1].Value = Customer_Nmae;
param[2] = new SqlParameter("@Address", SqlDbType.NVarChar, 100);
param[2].Value = Address;
param[3] = new SqlParameter("@Country", SqlDbType.NVarChar, 100);
param[3].Value = Country;
param[4] = new SqlParameter("@City", SqlDbType.NVarChar, 100);
param[4].Value = City;
param[5] = new SqlParameter("@Phone", SqlDbType.NVarChar, 100);
param[5].Value = Phone;
param[6] = new SqlParameter("@Fax", SqlDbType.NVarChar, 100);
param[6].Value = Fax;
param[7] = new SqlParameter("@Mobile", SqlDbType.NVarChar, 100);
param[7].Value = Mobile;
param[8] = new SqlParameter("@Email", SqlDbType.NVarChar, 100);
param[8].Value = Email;
param[9] = new SqlParameter("@Note", SqlDbType.NVarChar, 100);
param[9].Value = Note;
param[10] = new SqlParameter("@Cust_Imaige", SqlDbType.Image);
param[10].Value = Cust_Imaige;
param[11] = new SqlParameter("@Credit", SqlDbType.Decimal);
param[11].Value = Credit;
param[12] = new SqlParameter("@Debit", SqlDbType.Decimal);
param[12].Value = Debit;
param[13] = new SqlParameter("@Balance", SqlDbType.Decimal);
param[13].Value = Balance;
param[14] = new SqlParameter("@Statas", SqlDbType.Bit);
param[14].Value = Statas;
param[15] = new SqlParameter("@criterion", SqlDbType.NVarChar, 50);
param[15].Value = criterion;
DAL.ExecuteCommand("ADD_CUSTOMER", param);
DAL.close();
}
现在下面是我的客户表格
private void btn_Add_Click(object sender, EventArgs e)
{
try
{
byte[] Cust_Imaige;
if (pictureBox1.Image == null)
{
Cust_Imaige = new byte[0];
Customer.ADD_CUSTOMER(txt_Customer_Code.Text, txt_Customer_Nmae.Text, txt_Address.Text,
txt_Country.Text, txt_City.Text,txt_Phone.Text,txt_Fax.Text,txt_Mobail.Text,
txt_Email.Text, txt_Note.Text, Cust_Imaige,Convert.ToDecimal(txt_Credit.Text),
Convert.ToDecimal(txt_Debit.Text),Convert.ToDecimal(txt_Balance.Text),Convert.ToBoolean(txt_Statas.Text), "without_Image");
MessageBox.Show("added","add",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MemoryStream ms = new MemoryStream();
pictureBox2.Image.Save(ms, pictureBox2.Image.RawFormat);
Cust_Imaige = ms.ToArray();
Customer.ADD_CUSTOMER(txt_Customer_Code.Text, txt_Customer_Nmae.Text, txt_Address.Text,
txt_Country.Text, txt_City.Text, txt_Phone.Text, txt_Fax.Text, txt_Mobail.Text,
txt_Email.Text, txt_Note.Text, Cust_Imaige, Convert.ToDecimal(txt_Credit.Text),
Convert.ToDecimal(txt_Debit.Text), Convert.ToDecimal(txt_Balance.Text), Convert.ToBoolean(txt_Statas.Text), "with_Image");
MessageBox.Show("add","",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch
{
return;
}
finally
{
btn_Add.Enabled = false;
btn_New.Enabled = true;
}
}
Convert.ToBoolean(txt_Statas.Text)
将无法与1
和0
您应该使用Checkbox
并返回Checkbox.Checked
或者如果您想保留TextBox
则
替换Convert.ToBoolean(txt_Statas.Text)
为txt_Statas.Text == "1" ? true : false
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句