Friday, 25 October 2019

Conversion failed when converting the varchar value to data type int [closed]

Conversion failed when converting the varchar value to data type int [closed]



If you are getting  error than you have to so simply this


 public void dropExhibition(DropDownList Drop, string exid)
    {
        string value = "";
        SqlCommand cmd2 = new SqlCommand("Select * from Exhibition_Master where Exhibition_Status='Open'", con);
        SqlDataAdapter sda = new SqlDataAdapter(cmd2);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        foreach (DataRow dr in dt.Rows)
        {
            string s=dr["Team_Code"].ToString();
            string ex = dr["Exid"].ToString();
            string [] a = s.Split(',');
            foreach (var num in a)
            {
                if (num == exid)
                {
                    value +=ex +",";
                }
            }
        }


        cmd = new SqlCommand("select Distinct Exhibition_Name,Exid from dbo.Exhibition_Master where Exid IN(" + value.Trim(',') + ") and Exhibition_Status=@Exhibition_Status", con);
        cmd.Parameters.AddWithValue("@Exhibition_Status", "Open");


        try
        {
            con.Open();
            Drop.AppendDataBoundItems = true;
            Drop.DataSource = cmd.ExecuteReader();
            Drop.DataTextField = "Exhibition_Name";
            Drop.DataValueField = "Exid";
            Drop.DataBind();
        }
        catch (SqlException)
        {

        }
        finally
        {
            con.Close();
        }
}



No comments:

Post a Comment