服务器端连的方法返回一个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);
}
[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);
}
解决方案 »
- IIS发布网站后,div网页中css失效问题
- textbox focus on 的问题
- 急求谁有一个完整的关于asp.net2.0和NHibernate的例子给一份
- 用DataGrid超级联接列打开另外设置好大小的一个页面,怎么样设置。。。。。。
- IBM笔试题,大家一起看看啊....
- 求救:如何将几十万条数据从dataset或datagrid导出到客户端的excel,而又不太影响服务器的性能呢?
- ASP.net能否将数据载入剪切板以及能否将剪切板数据直接输出?
- asp.net页面中的全局变量
- 问一下两种数据库的差别
- 请教:当编辑DataGrid的记录时,如何控制文本框的长度?
- 解决ASP.NET中使用扫描仪的问题?
- 关于web打印急在线等!
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);
}
//得到数据源
[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"];
...
}
没试 你自己试吧
现在用ajaxpro的是不是很少了???
//得到数据源
[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"];
...
}
前台:
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;
}
'no exist ?
20楼很感谢你,但是alert什么也不显示
[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吗? 加个断点跟踪一下
public partial class ajax_GridViewDB : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax_GridViewDB));
}
}
写这个了吧?
摘该网站的例子出现以下错误
' value.Tables'为空或不是对象
{
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");
}
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;
}
够用就行 没必要学那么杂
AjaxPro.2.dll的这个版本
<!--
设置 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>
<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>
Tables[0]?
http://www.codeplex.com/AjaxPro/Release/ProjectReleases.aspx?ReleaseId=6179
我是在这里下的,应该是官方的地址吧.
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这个函数
弄字符串没有问题.就是DataSet有问题.
C#中return我检查了 也不为null
要是HTML中按照我的写 应该就没有错误那其他就真不知道是为什么错了仔细检查一下这两行代码:
只要你接收到的ds不为null的话 怎么都好办
var ds = ajaxstudy.SetData().value; //从后台接收ds return的值
var len = ds.Tables[0].Rows.length;
<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)
写的这个代码 结果是object 类型的。应该tostring() 拆箱后在赋值
其他版本試過,都有bug
我也出现这样的问题!
[email protected]