日期时间选择器转换时出错

发布于 2024-11-17 08:08:19 字数 2829 浏览 3 评论 0原文

这是我的错误 在此处输入图像描述

即使我尝试过: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
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光沙漏 2024-11-24 08:08:19

由于传递给 CNcommands 方法的最后一个参数而引发 FormatException

int.Parse("");

另请检查 Convert.ToDateTime("");//note如果您使用的是DateTimePicker,则无需解析为Convert.ToDateTime,因为dateTimePicker.ValueDateTime

还要检查 int.Parse(txt_sosmdn.Text)

但是您还应该考虑重构您的方法。

FormatException is thrown because of the last parameter you pass to the CNcommands method:

int.Parse("");

Check also the Convert.ToDateTime("");//note if you are using DateTimePicker then no need to parse to Convert.ToDateTime because the dateTimePicker.Value is DateTime.

And also check int.Parse(txt_sosmdn.Text)

However you should also consider re-factoring your method.

依 靠 2024-11-24 08:08:19

问题是您正在尝试将无效值解析为 int..
int.Parse 将数字的字符串表示形式转换为其等效的 32 位有符号整数。
该字符串必须是有效的数字,因此请在那里提供有效的数字..

就像

    int.Parse("0");

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

    int.Parse("0");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文