Hello, I created Ajax cascadingdownload list in my project. It worked fine in my localhost but when deployed it to my university's web server, the method error 500 was shown on page loaded. so the Firebug told me that the error is coming form "Conversion
failed when converting the nvarchar value 'BindCategory' to datatype Int." My code is below:
using System.Data;
using System.Web.Services;
using System.Collections.Generic;
using System.Collections.Specialized;
using AjaxControlToolkit;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Script.Services;
/// <summary>
/// Summary description for CascadingDropdown
/// </summary>
[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
//[WebService(Namespace = "http://www.stou.ac.th/Offices/ore/rere/goto/HelpDeskAdmin/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[System.Web.Script.Services.ScriptService]
//[System.Web.Script.Services.ScriptService()]
public class CascadingDropdown : System.Web.Services.WebService
{
[WebMethod]
public CascadingDropDownNameValue[] BindCategory(string knownCategoryValues, string category)
{
SqlConnection concatname = new SqlConnection(ConfigurationManager.ConnectionStrings["OREConnectionString"].ConnectionString);
concatname.Open();
SqlCommand cmdcatname = new SqlCommand("select * from HelpDeskCat where IsActive = 1", concatname);
SqlDataAdapter dacatname = new SqlDataAdapter(cmdcatname);
cmdcatname.ExecuteNonQuery();
DataSet dscatanme = new DataSet();
dacatname.Fill(dscatanme);
concatname.Close();
List<CascadingDropDownNameValue> catnamedetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtrow in dscatanme.Tables[0].Rows)
{
string CatID = dtrow["txtcatid"].ToString();
string CatName = dtrow["CatName"].ToString();
catnamedetails.Add(new CascadingDropDownNameValue(CatName, CatID));
}
return catnamedetails.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] BindSubCategory(string knownCategoryValues, string category)
{
Int32 CatID;
//string CatID;
StringDictionary subcatdetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
CatID = Convert.ToInt32(subcatdetails["CategoryName"]);
//CatID = subcatdetails["CategoryName"];
SqlConnection consubcat = new SqlConnection(ConfigurationManager.ConnectionStrings["OREConnectionString"].ConnectionString);
consubcat.Open();
SqlCommand cmdsubcat = new SqlCommand("select * from HelpDeskSubCat where catid = @catid", consubcat);
cmdsubcat.Parameters.Add("@catid", SqlDbType.Int).Value = CatID;
//cmdsubcat.Parameters.AddWithValue("@txtcatid", CatID);
cmdsubcat.ExecuteNonQuery();
SqlDataAdapter dasubcat = new SqlDataAdapter(cmdsubcat);
DataSet dsstate = new DataSet();
dasubcat.Fill(dsstate);
consubcat.Close();
List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtstaterow in dsstate.Tables[0].Rows)
{
string subcatID = dtstaterow["subcatid"].ToString();
string SubCatname = dtstaterow["subcatname"].ToString();
statedetails.Add(new CascadingDropDownNameValue(SubCatname, subcatID));
}
return statedetails.ToArray();
}
}
I wonder why the error is only appear when deploy that project on the Server. I try to find out the answers form google but no luck. Why different environment made my project error. Please give me an advise to solve this problem, Thanks
sorasak
0 Points
9 Posts
ajax cascadingdropdown Conversion failed method error 500
Apr 29, 2012 02:41 PM|LINK
Hello, I created Ajax cascadingdownload list in my project. It worked fine in my localhost but when deployed it to my university's web server, the method error 500 was shown on page loaded. so the Firebug told me that the error is coming form "Conversion failed when converting the nvarchar value 'BindCategory' to datatype Int." My code is below:
<table cellpadding="2" width="100%"> <tr> <td style="height:25px;"> <asp:Label ID="Label4" runat="server" CssClass="LabelTitle" Text="หมวดคำถาม:"></asp:Label> <asp:DropDownList ID="DDLCatName" runat="server" CssClass="DDLText"></asp:DropDownList> <asp:CascadingDropDown ID="CCCatName" runat="server" Category="CategoryName" TargetControlID="DDLCatName" PromptText="--โปรดเลือกหมวดคำถามหลัก--" LoadingText="Loading Categories.." ServiceMethod="BindCategory" ServicePath="CascadingDropdown.asmx"> </asp:CascadingDropDown> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DDLCatName" CssClass="failureNotification" ErrorMessage="โปรดเลือกหมวดคำถามหลัก" ></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="height:25px;"> <asp:Label ID="Label5" runat="server" CssClass="LabelTitle" Text="หมวดคำถามย่อย:"></asp:Label> <asp:DropDownList ID="DDLSubCatName" runat="server" CssClass="DDLText"></asp:DropDownList> <asp:CascadingDropDown ID="ccdSubCatName" runat="server" Category="SubCatName" ParentControlID="DDLCatName" TargetControlID="DDLSubCatName" PromptText="--โปรดเลือกหมวดคำถามย่อย--" LoadingText="Loading Sub Category.." ServiceMethod="BindSubCategory" ServicePath="CascadingDropdown.asmx"> </asp:CascadingDropDown> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DDLSubCatName" CssClass="failureNotification" ErrorMessage="โปรดเลือกหมวดคำถามย่อย" ></asp:RequiredFieldValidator> </td> </tr>Webservice Code:
using System.Data; using System.Web.Services; using System.Collections.Generic; using System.Collections.Specialized; using AjaxControlToolkit; using System.Configuration; using System.Data.SqlClient; using System.Web.Script.Services; /// <summary> /// Summary description for CascadingDropdown /// </summary> [ScriptService] [WebService(Namespace = "http://tempuri.org/")] //[WebService(Namespace = "http://www.stou.ac.th/Offices/ore/rere/goto/HelpDeskAdmin/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] //[System.Web.Script.Services.ScriptService] //[System.Web.Script.Services.ScriptService()] public class CascadingDropdown : System.Web.Services.WebService { [WebMethod] public CascadingDropDownNameValue[] BindCategory(string knownCategoryValues, string category) { SqlConnection concatname = new SqlConnection(ConfigurationManager.ConnectionStrings["OREConnectionString"].ConnectionString); concatname.Open(); SqlCommand cmdcatname = new SqlCommand("select * from HelpDeskCat where IsActive = 1", concatname); SqlDataAdapter dacatname = new SqlDataAdapter(cmdcatname); cmdcatname.ExecuteNonQuery(); DataSet dscatanme = new DataSet(); dacatname.Fill(dscatanme); concatname.Close(); List<CascadingDropDownNameValue> catnamedetails = new List<CascadingDropDownNameValue>(); foreach (DataRow dtrow in dscatanme.Tables[0].Rows) { string CatID = dtrow["txtcatid"].ToString(); string CatName = dtrow["CatName"].ToString(); catnamedetails.Add(new CascadingDropDownNameValue(CatName, CatID)); } return catnamedetails.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] BindSubCategory(string knownCategoryValues, string category) { Int32 CatID; //string CatID; StringDictionary subcatdetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); CatID = Convert.ToInt32(subcatdetails["CategoryName"]); //CatID = subcatdetails["CategoryName"]; SqlConnection consubcat = new SqlConnection(ConfigurationManager.ConnectionStrings["OREConnectionString"].ConnectionString); consubcat.Open(); SqlCommand cmdsubcat = new SqlCommand("select * from HelpDeskSubCat where catid = @catid", consubcat); cmdsubcat.Parameters.Add("@catid", SqlDbType.Int).Value = CatID; //cmdsubcat.Parameters.AddWithValue("@txtcatid", CatID); cmdsubcat.ExecuteNonQuery(); SqlDataAdapter dasubcat = new SqlDataAdapter(cmdsubcat); DataSet dsstate = new DataSet(); dasubcat.Fill(dsstate); consubcat.Close(); List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>(); foreach (DataRow dtstaterow in dsstate.Tables[0].Rows) { string subcatID = dtstaterow["subcatid"].ToString(); string SubCatname = dtstaterow["subcatname"].ToString(); statedetails.Add(new CascadingDropDownNameValue(SubCatname, subcatID)); } return statedetails.ToArray(); } }I wonder why the error is only appear when deploy that project on the Server. I try to find out the answers form google but no luck. Why different environment made my project error. Please give me an advise to solve this problem, Thanks
MethodError500