输入的字符串格式不正确 [英] input string was not incorrect format

查看:111
本文介绍了输入的字符串格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入字符串的格式不正确
请帮助我

input string was not incorrect format
Pls help me

private void BindGrid()
   {
       try
       {
           lblmsg.Text = "";


           incharge inch = new incharge();
           //DataTable dt = inch.SearchinchargeRecords()'
           DataTable dt = inch.Searchincharge( Convert.ToInt32(ddlcon.SelectedValue), Convert.ToInt32(ddlstate.SelectedValue), Convert.ToInt32(ddldistrict.SelectedValue), Convert.ToInt32(ddlblock.SelectedValue), Convert.ToInt32(ddldesignation.SelectedValue), txtname.Text, txtfathername.Text, Convert.ToInt32(txtinsanno.Text), Convert.ToInt32(txtmobileno.Text) );

           GridView1.DataSource = dt;
           GridView1.DataBind();

           lblcount.Text = "Total Records = " + dt.Rows.Count;

       }
       catch (Exception ex)
       {
           lblmsg.Text = "Error! " + ex.Message;
       }
   }


public DataTable Searchincharge(int countryid, int stateid, int districtid, int blockid, int designationid, string name, string fathername, int insanno, int mobileno)
   {
       CountryId = countryid;
       StateCountryId = stateid;
       DistrictStateId = districtid;
       BlockDistrictId = blockid;
       DesignationId = designationid;
       Name = name;
       FatherName = fathername;
       InsanNo = insanno;
       MobileNo = mobileno;

       try
       {
           string qry = "select * from inchargedetail inch left join country c on inch.country=c.countryid left join state s on inch.state=s.stateid left join district distt on inch.district=distt.districtid left join block b on inch.block=b.blockid left join designation d on inch.designation=d.designationid where 1 = 1";
           MySqlParameter countryidP, stateidP, districtidP, blockidP, designationidP, nameP, fathernameP, insannoP, mobilenoP;
           MySqlParameter[] p = { };
           if (countryid != 0)
           {
               qry += " and inch.country = @countryid";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               countryidP = new MySqlParameter("@countryid", CountryId);
               p[p.Length - 1] = countryidP;
           }
           if (StateCountryId != 0)
           {
               qry += " and inch.state = @statecountryid";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               stateidP = new MySqlParameter("@statecountryid", StateCountryId);
               p[p.Length - 1] = stateidP;
           }
           if (DistrictStateId != 0)
           {
               qry += " and inch.district = @districtstateid";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               districtidP = new MySqlParameter("@districtstateid", DistrictStateId);
               p[p.Length - 1] = districtidP;
           }
           if (BlockDistrictId != 0)
           {
               qry += " and inch.block = @blockdistrictid";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               blockidP = new MySqlParameter("@blockdistrictid", BlockDistrictId);
               p[p.Length - 1] = blockidP;
           }
           if (designationid != 0)
           {
               qry += " and inch.designation=@designationid";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               designationidP = new MySqlParameter("@designationid", DesignationId);
               p[p.Length - 1] = designationidP;
           }

           if (name != "")
           {
               qry += " and inch.inchargename=@name";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               nameP = new MySqlParameter("@name", Name);
               p[p.Length - 1] = nameP;
           }

           if (fathername != "")
           {
               qry += " and inch.fathername=@fathername";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               fathernameP = new MySqlParameter("@fathername", FatherName);
               p[p.Length - 1] = fathernameP;
           }

           if (insanno > 0)
           {
               qry += " and inch.insanno=@insanno";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               insannoP = new MySqlParameter("@insanno", InsanNo);
               p[p.Length - 1] = insannoP;
           }

           if (mobileno > 0)
           {
               qry += " and inch.mobileno=@mobileno";
               Array.Resize<MySqlParameter>(ref p, p.Length + 1);
               mobilenoP = new MySqlParameter("@mobileno", MobileNo);
               p[p.Length - 1] = mobilenoP;
           }

           return MySqlHelper.ExecuteDataset(common.GetConnectionString(), qry, p).Tables[0];

       }
       catch
       {
           Exception ex = new Exception("Search InchargeDetail Error.");
           throw ex;
       }


   }

推荐答案



请快速查看每个参数的值.

Hi,

Please check the value of each parameter by quick watch.

DataTable dt = inch.Searchincharge( Convert.ToInt32(ddlcon.SelectedValue),
Convert.ToInt32(ddlstate.SelectedValue), 
Convert.ToInt32(ddldistrict.SelectedValue), 
Convert.ToInt32(ddlblock.SelectedValue), 
Convert.ToInt32(ddldesignation.SelectedValue), 
txtname.Text, 
txtfathername.Text, 
Convert.ToInt32(txtinsanno.Text), 
Convert.ToInt32(txtmobileno.Text));

特别是您要转换为int的值.我认为任何值都具有带有char值的字符串,这不能令人垂涎.

如果仍然找不到解决方案,则将代码放在try catch块中,并在此处复制异常stacktrace.

Specially the value which you are converting into int. I think any of the value has string with char value which is not conveting.

If still you are not able to find the solution then put the code in try catch block and copy the exception stacktrace here.


检查您传递给searchincharge()的参数类型将字符串传递给int,反之亦然.
Check the Parameters type that u r passing to searchincharge() either you are passing string to int or Vice versa.


这篇关于输入的字符串格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆