这是我的错误
即使我尝试过:dtp_ngaycap.Value
它仍然证实了我的错误。
这是CNcommands
类
public bool CNcommands(string commandType,string tenchunha,string nguoidaidien, string chucvu, int soCMDN, DateTime ngaycap, string diachi, string masothue, string nguoithuhuong, string sotaikhoan,string nganhang,string sodienthoai, string diachiemail, string diachinganhang, int maCN)
{
if (commandType == "insert")
{
string insertCN = "INSERT INTO [QLThueNha].[dbo].[ChuNha][MaChuNha],[TenChuNha],[Nguoidaidien],[Chucvu],[SoCMND],[Ngaycap],[Diachi],[Masothue],[Nguoithuhuong],[Sotaikhoan],[Nganhang],[Sodienthoai],[DiachimailCN],[Diachinganhang])VALUES('" + tenchunha + "','" + nguoidaidien + "','" + chucvu + "','" + soCMDN + "','" + ngaycap + "','" + diachi + "','" + masothue + "','" + nguoithuhuong + "','" + sotaikhoan + "','" + nganhang + "','" + sodienthoai + "','" + diachiemail + "','" + diachinganhang + "')";
if (executeQuery(insertCN, ref rowAffect_) == true && rowAffect_ == 1)
{
return true;
}
return true;
}
else if (commandType == "update")
{
string updateCN = "UPDATE [QLThueNha].[dbo].[ChuNha] SET [TenChuNha] = '" + tenchunha + "',[Nguoidaidien] = '" + nguoidaidien + "',[Chucvu] = '" + chucvu + "',[SoCMND] = '" + soCMDN + "',[Ngaycap] = '" + ngaycap + "',[Diachi] = '" + diachi + "',[Masothue] = '" + masothue + "',[Nguoithuhuong] = '" + nguoithuhuong + "',[Sotaikhoan] = '" + sotaikhoan + "',[Nganhang] = '" + nganhang + "',[Sodienthoai] = '" + sodienthoai + "',[DiachimailCN] = '" + diachiemail + "',[Diachinganhang] = '" + diachinganhang + "' WHERE <Search Conditions,,>";
if (executeQuery(updateCN, ref rowAffect_) == true && rowAffect_ == 1)
{
return true;
}
return true;
}
else
{
return false;
}
//if (commandType == "delete")
//{
// string deleteCN = "SET [TenChuNha] = '" + tenchunha + "',[Nguoidaidien] = '" + nguoidaidien + "',[Chucvu] = '" + chucvu + "',[SoCMND] = '" + soCMDN + "',[Ngaycap] = '" + ngaycap + "',[Diachi] = '" + diachi + "',[Masothue] = '" + masothue + "',[Nguoithuhuong] = '" + nguoithuhuong + "',[Sotaikhoan] = '" + sotaikhoan + "',[Nganhang] = '" + nganhang + "',[Sodienthoai] = '" + sodienthoai + "',[DiachimailCN] = '" + diachiemail + "',[Diachinganhang] = '" + diachinganhang + "' WHERE <Search Conditions,,>";
// if (executeQuery(deleteCN, ref rowAffect_) == true && rowAffect_ == 1)
// {
// return true;
// }
//}
}
答案 0 :(得分:2)
FormatException
方法的最后一个参数,会抛出 CNcommands
:
int.Parse("");
如果您使用Convert.ToDateTime("");
,请检查DateTimePicker
//注意,然后无需解析为Convert.ToDateTime
,因为dateTimePicker.Value
为DateTime
。
并检查int.Parse(txt_sosmdn.Text)
但是你也应该考虑重新分解你的方法。
答案 1 :(得分:0)
问题是你试图将无效值解析为int .. int.Parse将number的字符串表示形式转换为其32位有符号整数等价物。 并且该字符串必须是有效数字,因此在那里提供有效数字..
像
int.Parse("0");