Suresh chinna

Suresh chinna

  • NA
  • 2
  • 1.6k

how do i read c# list using java script

Aug 27 2014 8:48 AM
here is my web service method(c#)
[WebMethod]
public List<Errors> GetPostings()
{
string connetionString = null;
SqlConnection cnn ;
connetionString = "Data Source=WIN-B5SQAAB3195.\\SCOM;Initial Catalog=Portal;Integrated Security=True";
cnn = new SqlConnection(connetionString);
const string SQL = "select dates,value from errors";
SqlCommand myCommand = new SqlCommand(SQL, cnn);
cnn.Open();
myCommand.ExecuteNonQuery();
// myConnection.Close();
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = myCommand;
DataSet DSet = new DataSet();
dataAdapter.Fill(DSet);
List<Errors> errors = new List<Errors>();
foreach (DataRow row in DSet.Tables[0].Rows)
{
Errors jp = new Errors();
jp.date = (DateTime)row["DATES"];
jp.values = (int)row["value"];
//jp.Id = (int)row["Id"];
//jp.JobPost = row["JobPosting"].ToString();
//jp.Applicant = row["Applicant"].ToString();
//jp.Type = row["Type"].ToString();
errors.Add(jp);
}
return errors;
}
here is my java script which has to read the list which is returned by the above code
$(function () {
$('#Button1').click(getPosts);
});
function getPosts() {
OpenEMRWebService.Service1.GetPostings();
try {
$.ajax({
type: "post",
url: "Service1.asmx/GetPostings",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var jposts = response.d;
$('#output').empty();
$.each(jposts, function (index, jpost) {
$('#output').append('<p><strong>Job Posting: ' + jpost.dates + '</strong><br />Job Id: ' +
jpost.value + '<br />Internal/External: ' +
'</p>');
});
},
failure: function (msg) {
$('#output').text(msg);
}
});
}
catch (e) {
alert(1);
}
}
but it not returning any values  can any one help doing this?
thanx in advance