I want to get the multiple field from parameterized select query in web method using AJAX in asp.net C#.
Here is my web method query:
[WebMethod]
[ScriptMethod]
public static string GetSchoolName(string schoolName)
{
try
{
using (var con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
using (var cmd = new SqlCommand("select abc, xyz, pqr from tbl_schoolregistration where name = @schoolname", con))
{
cmd.Parameters.Add("@schoolname", SqlDbType.NVarChar).Value = schoolName;
con.Open();
object val = cmd.ExecuteScalar();
return val == DBNull.Value ? "" : ((Int32)val).ToString();
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
Now in this query only abc is getting that is int. While the xyz and pqr is not getting (I have checked this using debug mode).
Here is client side code
var c = $find("<%=cmbobx_search.ClientID %>");
$.ajax({
type: "POST",
url: "schoolregistration.aspx/GetSchoolName",
data: JSON.stringify({ schoolName: c.get_textBoxControl().value }),
contentType: "application/json; charset=utf-8",
datatype: "json",
success: OnSuccessGetSchoolName,
failure: function () {
alert("error! try again...");
}
});
function OnSuccessGetSchoolName(response) {
var c = $find("<%=hdn_abc.ClientID %>");
var d = $find("<%=txt_xyz.ClientID %>");
var e = $find("<%=txt_pqr.ClientID %>");
document.getElementById('<%= hdn_abc.ClientID%>').value = response.c;
document.getElementById('<%= txt_xyz.ClientID %>').value = d.get_textBoxControl().value
document.getElementById('<%= txt_pqr.ClientID %>').value = e.get_textBoxControl().value
}
So, what I want to do for getting all field which is in select query. May I use the loop or any other thing?