input string was not incorrect format
Pls help me
private void BindGrid()
{
try
{
lblmsg.Text = "";
incharge inch = new incharge();
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;
}
}