ajax在ASP.NET中如何读取数据库
我的CS代码protectedvoidPage_Load(objectsender,EventArgse){Response.Expires=-1;SqlConnecti...
我的CS代码
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
SqlConnection myConn = CC.GetConnection();
myConn.Open();
string sqlStr = "select * from stuSusheInfo where 姓名=";
sqlStr=sqlStr+"'"+Request.QueryString["name"]+"'";
SqlCommand myCmd = new SqlCommand(sqlStr, myConn);
SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
DataSet myDs = new DataSet();
myDa.Fill(myDs, "Table");
System.Data.DataTable dt;
dt = myDs.Tables["Table"];
foreach (System.Data.DataColumn dc in dt.Columns)
{
dc.ColumnMapping = System.Data.MappingType.Attribute;
}
myDa.Dispose();
myDs.Dispose();
myConn.Close();
}
我参考的原始例子是:http://www.w3school.com.cn/ajax/ajax_database.asp,这个例子是ASP,我想用ASP.NET,就是读取数据库,并进而生成XML文件,这个步骤不会写,运行不成功,请各位网友帮帮忙,谢谢!
运行还是不成功,所有源代码,在这里,我的空间
http://hi.baidu.com/vincent316/blog/item/178fcc3c28dec7ce9f3d62c6.html 展开
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
SqlConnection myConn = CC.GetConnection();
myConn.Open();
string sqlStr = "select * from stuSusheInfo where 姓名=";
sqlStr=sqlStr+"'"+Request.QueryString["name"]+"'";
SqlCommand myCmd = new SqlCommand(sqlStr, myConn);
SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
DataSet myDs = new DataSet();
myDa.Fill(myDs, "Table");
System.Data.DataTable dt;
dt = myDs.Tables["Table"];
foreach (System.Data.DataColumn dc in dt.Columns)
{
dc.ColumnMapping = System.Data.MappingType.Attribute;
}
myDa.Dispose();
myDs.Dispose();
myConn.Close();
}
我参考的原始例子是:http://www.w3school.com.cn/ajax/ajax_database.asp,这个例子是ASP,我想用ASP.NET,就是读取数据库,并进而生成XML文件,这个步骤不会写,运行不成功,请各位网友帮帮忙,谢谢!
运行还是不成功,所有源代码,在这里,我的空间
http://hi.baidu.com/vincent316/blog/item/178fcc3c28dec7ce9f3d62c6.html 展开
展开全部
foreach (System.Data.DataColumn dc in dt.Columns)
{
dc.ColumnMapping = System.Data.MappingType.Attribute;
}
Response.Write(myDs.GetXml());
myDa.Dispose();
myDs.Dispose();
myConn.Close();
Response.End();
这个aspx将生成纯xml文本,然后ajax从这个页面获得xml.
{
dc.ColumnMapping = System.Data.MappingType.Attribute;
}
Response.Write(myDs.GetXml());
myDa.Dispose();
myDs.Dispose();
myConn.Close();
Response.End();
这个aspx将生成纯xml文本,然后ajax从这个页面获得xml.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询