首页上一页 1 下一页尾页 1 条记录 1/1页
我在用贵司的书做题时老是不支持关键字和转义子符
发表在ASP.NET图书答疑
2010-09-08
是否精华
是
否
版块置顶:
是
否
书籍:ASP.net 从入门到精通
第十章mr\sl\10\05
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridViewBind();
}
}
public void GridViewBind()
{
//实例化SqlConnection对象
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = "server= WIN-AETOFIY9XM3\SQLEXPRESS;uid=sa;pwd='123456';database=db_student";
//定义SQL语句
string SqlStr = "select * from tb_StuInfo";
//实例化SqlDataAdapter对象
SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon);
//实例化数据集DataSet
DataSet ds = new DataSet();
da.Fill(ds, "tb_StuInfo");
//绑定DataList控件
GridView1.DataSource = ds;//设置数据源,用于填充控件中的项的值列表
GridView1.DataBind();//将控件及其所有子控件绑定到指定的数据源
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridViewBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
首先他在这里不支持转义子符
server= WIN-AETOFIY9XM3\SQLEXPRESS;uid=sa;pwd='123456';database=db_student";
我将他改为WIN-AETOFIY9XM3\\SQLEXPRESS如此,
但是问题又来拉:
da.Fill(ds, "tb_StuInfo");在这里出现了异常,没法解决。请帮忙解决,谢谢!
第十章mr\sl\10\05
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridViewBind();
}
}
public void GridViewBind()
{
//实例化SqlConnection对象
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = "server= WIN-AETOFIY9XM3\SQLEXPRESS;uid=sa;pwd='123456';database=db_student";
//定义SQL语句
string SqlStr = "select * from tb_StuInfo";
//实例化SqlDataAdapter对象
SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon);
//实例化数据集DataSet
DataSet ds = new DataSet();
da.Fill(ds, "tb_StuInfo");
//绑定DataList控件
GridView1.DataSource = ds;//设置数据源,用于填充控件中的项的值列表
GridView1.DataBind();//将控件及其所有子控件绑定到指定的数据源
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridViewBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
首先他在这里不支持转义子符
server= WIN-AETOFIY9XM3\SQLEXPRESS;uid=sa;pwd='123456';database=db_student";
我将他改为WIN-AETOFIY9XM3\\SQLEXPRESS如此,
但是问题又来拉:
da.Fill(ds, "tb_StuInfo");在这里出现了异常,没法解决。请帮忙解决,谢谢!