Son
Son

Reputation: 129

error datetime picker converting

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;
        //    }
        //}

    }

Upvotes: 1

Views: 1033

Answers (2)

Jalal Said
Jalal Said

Reputation: 16162

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.

Upvotes: 2

Syeda
Syeda

Reputation: 1205

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");

Upvotes: 0

Related Questions