服务器端连的方法返回一个DataSet,但没有对象
[AjaxPro.AjaxMethod]
    public DataSet  SetData()
    {
        SqlConnection con = new SqlConnection("Data Source=MS-F64B36A49ABB;Initial Catalog=pubs;Integrated Security=True");
        SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "jobs"); 
        return ds;
    }
function Button3_onclick() {
ajaxstudy.SetData(aa);
}
function aa(dst)
{
    
    var str=dst.value.Tables[0].Columns.length;    alert('asdasd'+str);
}

解决方案 »

  1.   

    [AjaxPro.AjaxMethod] 
        public string SetData() 
        { 
            SqlConnection con = new SqlConnection("Data Source=MS-F64B36A49ABB;Initial Catalog=pubs;Integrated Security=True"); 
            SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con); 
            DataSet ds = new DataSet(); 
            sda.Fill(ds, "jobs");  
            return ds.Tables[0].Columns.length;; 
        } function aa(dst) 

         
        var str=SetData();     alert( 'asdasd '+str); 
    }
      

  2.   

    我就想返回一个DataSet到客客户端
      

  3.   

    http://blog.csdn.net/blues07/archive/2007/05/30/1630797.aspx
      

  4.   

    datatable也不行,只有string可以,帮忙呀.
      

  5.   

    C#:
        //得到数据源
        [AjaxPro.AjaxMethod]
        public DataSet GetDataSource()
        {
            string sql = "select * from UserInfo where UserID = " + Session["uid"].ToString();
            zylink.conString();
            DataSet ds = zylink.GetDataSource(sql);
            return ds;
        }HTML:
    //AJAX方法调用要修改的记录的数据集
        var ds = ajax_GridViewDB.GetDataSource().value;
     if(ds!=null)
        {
            uname.value = ds.Tables[0].Rows[0]["UserName"];
            upwd.value = ds.Tables[0].Rows[0]["UserPwd"];
            againpwd.value = ds.Tables[0].Rows[0]["UserPwd"];
            realname.value = ds.Tables[0].Rows[0]["RealName"];
            cname.value = ds.Tables[0].Rows[0]["CompanyName"];
    ...
        }
      

  6.   

    ds.Tables[0].Rows.length  or ds.Tables[0].Rows.Count
    没试 你自己试吧
      

  7.   

    不明白为什么字符串没问题就是dataset显示缺少对象呢
      

  8.   

    就是不返回DataSet,不知道是什么原因,总提示缺少对象.
    现在用ajaxpro的是不是很少了???
      

  9.   

    不好用,俺试了,现在只有字符串的好用,DataSet and DataTable都不好用.
      

  10.   

    AjaxPro.2.dll 2007-7-31 我用的是这个版本的
      

  11.   

    C#: 
        //得到数据源 
        [AjaxPro.AjaxMethod] 
        public DataSet GetDataSource() 
        { 
            string sql = "select * from UserInfo where UserID = " + Session["uid"].ToString(); 
            zylink.conString(); 
            DataSet ds = zylink.GetDataSource(sql); 
            return ds; 
        } HTML: 
    //AJAX方法调用要修改的记录的数据集 
        var ds = ajax_GridViewDB.GetDataSource().value; 
     if(ds!=null) 
        { 
            uname.value = ds.Tables[0].Rows[0]["UserName"]; 
            upwd.value = ds.Tables[0].Rows[0]["UserPwd"]; 
            againpwd.value = ds.Tables[0].Rows[0]["UserPwd"]; 
            realname.value = ds.Tables[0].Rows[0]["RealName"]; 
            cname.value = ds.Tables[0].Rows[0]["CompanyName"]; 
    ... 
        }
      

  12.   

    感谢你的帮助,但是真的不好用.
    前台:
    function Button3_onclick() {
    var ds=ajaxstudy.SetData().value;
    if(ds!=null)
        {
            alert('exist');
        }
        else
        {
            alert('no exist');
        }
    }
    后台:
    [AjaxPro.AjaxMethod]
        public DataSet    SetData()
        {
            SqlConnection con = new SqlConnection("Data Source=MS-F64B36A49ABB;Initial Catalog=pubs;Integrated Security=True");
            SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con);
            DataSet ds = new DataSet();
            sda.Fill(ds, "jobs");
            return ds;
        }
      

  13.   

    alert显示的是什么?
    'no exist ?
      

  14.   

    http://b.thec.cn/sonce/?tid=89
      

  15.   

    21楼这是什么网址???
    20楼很感谢你,但是alert什么也不显示
      

  16.   

    你确保你这段代码
    [AjaxPro.AjaxMethod] 
        public DataSet    SetData() 
        { 
            SqlConnection con = new SqlConnection("Data Source=MS-F64B36A49ABB;Initial Catalog=pubs;Integrated Security=True"); 
            SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con); 
            DataSet ds = new DataSet(); 
            sda.Fill(ds, "jobs"); 
            return ds; 
        }返回的ds不是null吗?  加个断点跟踪一下
      

  17.   

    我确定这个ds不是null,已经跟踪过了.
      

  18.   

    那后台ds不为空  就是前台没有接收到ds的值 是吧?那你后台写了:
    public partial class ajax_GridViewDB : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax_GridViewDB));
        }
    }
    写这个了吧?
      

  19.   

    http://www.ajaxpro.info/Examples/DataSets/default.aspx
    摘该网站的例子出现以下错误
    ' value.Tables'为空或不是对象
      

  20.   

    你把你关键的代码 HTML和C#的都贴上来我看看
      

  21.   

    public partial class ajaxstudy : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxstudy));
        }
     [AjaxPro.AjaxMethod]
        public DataSet    SetData()
        {
            SqlConnection con = new SqlConnection("Data Source=MS-F64B36A49ABB;Initial Catalog=pubs;Integrated Security=True");
            SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con);
            DataSet ds = new DataSet();
            sda.Fill(ds, "jobs");
            return ds;
        }
    function Button3_onclick() {ajaxstudy.SetData(aa);
    }
    function aa(res)
    {
        var cols = res.value.Tables[0].Columns.length;
        var rows = res.value.Tables[0].Rows.length;
        
        alert(cols + " cols and " + rows + " rows");
    }
      

  22.   

    <input id="Button3" type="button" value="button" onclick="return Button3_onclick()" />
      

  23.   

    你怎么写,我刚试过没问题:
    HTML:
    ------------------------------------------
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">    
        function aa()
        {
            var ds = ajaxstudy.SetData().value;
            var len = ds.Tables[0].Rows.length;
            if(ds != null)
            {
                alert(len);
            }
            else
            {
                alert('kkkkkkkkkkk');
            }
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <input id="Button3" type="button" value="button" onclick="aa();" / >
        </div>
        </form>
    </body>
    C#:
    ------------------------------------------------
    protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxstudy));
        }    [AjaxPro.AjaxMethod]
        public DataSet SetData()
        {
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=pubs;Integrated Security=True");
            SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con);
            DataSet ds = new DataSet();
            sda.Fill(ds, "jobs");
            return ds;
        } 
      

  24.   

    行,你怎么写都行,只要好用就可以.现在除微软那些ajax外,还用什么框架?
      

  25.   

    反正我就用 ajaxpro.dll  别的一般不怎么用
    够用就行  没必要学那么杂
      

  26.   

    2007-7-31
    AjaxPro.2.dll的这个版本
      

  27.   

    <system.web>
    <!-- 
                设置 compilation debug="true" 将调试符号插入
                已编译的页面中。但由于这会 
                影响性能,因此只在开发过程中将此值 
                设置为 true。
            -->
    <compilation debug="true"/>
    <!--
                通过 <authentication> 节可以配置 ASP.NET 使用的 
                安全身份验证模式,
                以标识传入的用户。 
            -->
    <authentication mode="Windows"/>
    <!--
                如果在执行请求的过程中出现未处理的错误,
                则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
                开发人员通过该节可以配置
                要显示的 html 错误页
                以代替错误堆栈跟踪。        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
        <httpHandlers>
          <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
        </httpHandlers>
      </system.web>
      

  28.   

    <configuration>
    <appSettings/>
      <connectionStrings>
        <add name="ConnDB" connectionString="Data Source=.;Initial Catalog=Demo;User ID=sa;password=;" providerName="System.Data.SqlClient"/>
      </connectionStrings>
    <system.web>
        <httpHandlers>
          <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
        </httpHandlers>
      

  29.   

    什么缺少对象啊?
    Tables[0]?
      

  30.   

    latest version 6.10.6.1.
    http://www.codeplex.com/AjaxPro/Release/ProjectReleases.aspx?ReleaseId=6179
    我是在这里下的,应该是官方的地址吧.
      

  31.   

    我觉得你就算把我上面给你的代码沾过去也应该没有错了 <script type="text/javascript" >     
        function aa() 
        { 
            var ds = ajaxstudy.SetData().value; 
            var len = ds.Tables[0].Rows.length; 
            if(ds != null) 
            { 
                alert(len); 
            } 
            else 
            { 
                alert( 'kkkkkkkkkkk '); 
            } 
        } 
         </script > 
    </head > 
    <body > 
         <form id="form1" runat="server" > 
         <div > 
         <input id="Button3" type="button" value="button" onclick="aa();" /  > 调用的是aa这个函数
      

  32.   

    我就是新建页把你写的贴上去了,导了一下命名空间,再没弄别的.
    弄字符串没有问题.就是DataSet有问题.
      

  33.   

    web.config中配置的没有错误
    C#中return我检查了 也不为null
    要是HTML中按照我的写 应该就没有错误那其他就真不知道是为什么错了仔细检查一下这两行代码:
    只要你接收到的ds不为null的话 怎么都好办
    var ds = ajaxstudy.SetData().value; //从后台接收ds return的值 
    var len = ds.Tables[0].Rows.length; 
      

  34.   

    我用火狐打开,有两个错误如下:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head>
    <body>
    </body>
    </html>
    POST http://localhost:2857/WebSite8/ajaxpro/Default9,App_Web_qdw7_eo8.ashx (31ms)core.ashx (line 432)
    ParamsHeadersPostResponse
    Response Headers
    Request Headers{"value":new Ajax.Web.DataSet([new Ajax.Web.DataTable([["job_id","System.Int16"],["job_desc","System.String"],["min_lvl","System.Byte"],["max_lvl","System.Byte"]],[[1,"New Hire - Job not specified",10,10],[2,"Chief Executive Officer",200,250],[3,"Business Operations Manager",175,225],[4,"Chief Financial Officier",175,250],[5,"Publisher",150,250],[6,"Managing Editor",140,225],[7,"Marketing Manager",120,200],[8,"Public Relations Manager",100,175],[9,"Acquisitions Manager",75,175],[10,"Productions Manager",75,165],[11,"Operations Manager",75,150],[12,"Editor",25,100],[13,"Sales Representative",25,100],[14,"Designer",25,100]])])}Ajax.Web.DataTable is not a constructor
    createResponse(Object, undefined)core.ashx (line 366)
    invoke("SetData", Object, undefined, undefined)core.ashx (line 435)
    invoke("SetData", Object, [null, null, null, 3 more...])core.ashx (line 534)
    SetData()Default9,App_Web_... (line 4)
    aa()Default9.aspx (line 12)
    onclick(click clientX=0, clientY=0)Default9.aspx (line 1)
    [Break on this error] eval("v = " + responseText + ";");
    core.ashx (line 366)
    this.onTimeout is not a function
    timeout()core.ashx (line 381)
    (no name)()prototype.ashx (line 59)
    [Break on this error] var r = this.onTimeout(this.duration, this);
    core.ashx (line 381)
      

  35.   

    给我一份呗,[email protected],谢谢啊
      

  36.   

    我觉得跟ajaxpro.dll没有关系因为就算你在HTML不使用ajax的话,HTML中本身也包含dataset这个对象
      

  37.   

    好用了,万分感谢,是DLL的问题,你是在那里下的?
      

  38.   

    dataset 和dataTable 是服务器的内存中的一个表结构,那个好像不能返回给客户端吧,服务器给客户端的都是代码都是在服务器端编译好的,你那样做不,不是要服务器不编译发给你客户端么,还有楼顶那个兄弟 ds.Tables[0].Rows[0]["UserName"]
    写的这个代码 结果是object 类型的。应该tostring() 拆箱后在赋值
      

  39.   

    對,就這個还是用6.10.6.1吧!
    其他版本試過,都有bug
      

  40.   

    能发一个给我吗?[email protected]
    我也出现这样的问题!
      

  41.   

    能不能也发一份给我,我也遇到一样的问题...
    [email protected]