Click here to Skip to main content
15,441,434 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
input string was not incorrect format
Pls help me

C#
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;
       }
   }

C#
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;
       }


   }
Posted
Comments
David Goebet 22-Nov-12 5:38am     CRLF
what ? what is the problem ?
Mohd. Mukhtar 22-Nov-12 5:39am    
On which line are you getting error?
pankajgarg1986 22-Nov-12 5:41am    
sir, when call searchincharge() function then show error! input string is not in correct formate
pankajgarg1986 22-Nov-12 5:53am    
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) );
Herman<T>.Instance 22-Nov-12 5:54am     CRLF
have you done a debug? do you know the values for the variables? perhaps: lblcount.Text = "Total Records = " + dt.Rows.Count; should be lblcount.Text = "Total Records = " + dt.Rows.Count.ToString();

Hi,

Please check the value of each parameter by quick watch.

C#
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));
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.
 
Share this answer
 
v2
Check the Parameters type that u r passing to searchincharge() either you are passing string to int or Vice versa.
 
Share this answer
 
Comments
pankajgarg1986 22-Nov-12 5:59am    
Parameters type is correct

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900