日期时间选择器转换时出错
这是我的错误
即使我尝试过: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;
// }
//}
}
here is my error
even i tried: dtp_ngaycap.Value
it still confirms me that error.
here is the code of CNcommands
class
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;
// }
//}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于传递给
CNcommands
方法的最后一个参数而引发FormatException
:另请检查
Convert.ToDateTime("");
//note如果您使用的是DateTimePicker
,则无需解析为Convert.ToDateTime
,因为dateTimePicker.Value
是DateTime
。还要检查
int.Parse(txt_sosmdn.Text)
但是您还应该考虑重构您的方法。
FormatException
is thrown because of the last parameter you pass to theCNcommands
method:Check also the
Convert.ToDateTime("");
//note if you are usingDateTimePicker
then no need to parse toConvert.ToDateTime
because thedateTimePicker.Value
isDateTime
.And also check
int.Parse(txt_sosmdn.Text)
However you should also consider re-factoring your method.
问题是您正在尝试将无效值解析为 int..
int.Parse 将数字的字符串表示形式转换为其等效的 32 位有符号整数。
该字符串必须是有效的数字,因此请在那里提供有效的数字..
就像
The problem is you are trying to parse an invalid value to int..
int.Parse converts the string representation of number to its 32-bit signed integer equivalent..
And that string must be a valid number so provide a valid number there..
like