开发者

How can i see datatable which is the return from a webservice method

I am trying use a datatable from a web service method. I can see return value when it's a string data. This my code and it returns an alert hatada : null

 $.ajax(
            {
                type: 'POST',
                url: 'http://localhost:40764/HastaTahlilUyariServisi.asmx/Hello',
                data: "{_sTcKimlikNo: '111111111111', _iKlinikKodu:121212, _bAy:12, _iYil:2009}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(ajaxCevap) {
                    alert('basarili: ' + ajaxCevap); //$('#dv').html(ajaxCevap.d);
                },
                error: function(xhr, status) {                   
                    alert("hatada:" + xhr.responseXML);
                },
                beforeSend: function() {
                    alert('gonderilecek');
                },
                afterSend: function() {
                    alert('gonderildi');
                },
                complete: function(xhr, status) {
                    if (status == 'success')
                        alert('success' + $.httpData(xhr));
                }
            }

and this is my webservice method:

  [WebMethod]
    public DataTable Hello(string _sTcKimlikNo, int _iKlinikKodu, byte _bAy, int _iYil)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ad");
        DataRow rw = dt.NewRow();
        rw[0] = _sTcKimlikNo + " " + _iKlinikKodu + " " + _bAy + " " + _iYil;
        return dt;
    }

How can i see datat开发者_JAVA百科able from webservice method? Thanks in advance.


No Serialization problem, just name your datatable and that will solve the problem.

public DataTable LineChrt() {
  string query = "select m.class,sum(m.plannedvisits)" + 
    "plannedvisits,sum(m.actualvisits) actualvisits from vw_MTD_TgtVsAct_Calls1 m " +
    "where 1=1 and m.class in ('A','B','C')  and m.month = 6 " +
    "group by m.class";
  string constr = System.Configuration
    .ConfigurationSettings.AppSettings["PocketDCR"];
  DataTable data = new DataTable();
  SqlDataAdapter LCData = new SqlDataAdapter(query,constr);
  LCData.Fill(data);
  data.TableName = "ChartData";
  return data;
}


I don't think you can return a DataTable from a web service due to serialisation problems. This Microsoft article suggests returning a DataSet instead:
Problems using an XML Web service that returns a DataTable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜