ASP NET动态网站开发基础教程习题答案(3)

2019-01-19 13:20

bsp;             

Chap06 参考答案

一、1.Connection Command DataSetCommand DataSet DataReader 2.数据处理 Connection Command DataReader DataAdapter 3.User ID(uid) Password(pwd) 用户ID 口令 4.SqlDataSource ACCESS 密码 ACCESS

5.数据命令 数据库连接 填充 DataSet 更新数据源 DataSet 二、1.B 2.AC 3.A 4.A 5.ABCD 三、上机操作题

1、ex6_1.aspx.cs的源代码如下:

protected void Page_Load(object sender, EventArgs e) {

String sqlconn = \Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\\\Database\\\\asp3.5Basic\\\\BookStore.mdb\

OleDbConnection myConnection = new OleDbConnection(sqlconn); myConnection.Open();

OleDbCommand myCommand = new OleDbCommand(\OleDbDataReader myReader;

myReader = myCommand.ExecuteReader();

Response.Write(\使用OleDbCommand类读取数据


\Response.Write(\Response.Write(\for (int i = 0; i < myReader.FieldCount; i++) {

Response.Write(\}

Response.Write(\while (myReader.Read()) {

Response.Write(\

for (int i = 0; i < myReader.FieldCount; i++) {

Response.Write(\}

Response.Write(\}

Response.Write(\myReader.Close();

myConnection.Close(); }

2、ex6_2.aspx的源代码如下: <%@ Page Language=\AutoEventWireup=\Inherits=\

使用DataApapter读取Access数据库

Ex6_2.aspx.cs的主要代码如下:

protected void Page_Load(object sender, EventArgs e) { string ConnectionStr = \Provider=Microsoft.Jet.OLEDB.4.0;Data Source= E:\\\\Database\\\\asp3.5Basic\\\\BookStore.mdb \

OleDbConnection myConn = new OleDbConnection(ConnectionStr); myConn.Open();

OleDbCommand myCommand = new OleDbCommand(\OleDbDataAdapter Adapter = new OleDbDataAdapter(); Adapter.SelectCommand = myCommand; DataSet myDs = new DataSet(); Adapter.Fill(myDs);

GridView1.DataSource = myDs.Tables[0].DefaultView; GridView1.DataBind(); myConn.Close(); }

3、ex6_3.aspx.cs的主要代码如下:

public partial class ex6_3 : System.Web.UI.Page {

void CreateXmlDocument(string file) {

XmlDocument doc = new XmlDocument();

XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration(\

doc.InsertBefore(xmlDeclaration, doc.DocumentElement); XmlElement rootNode = doc.CreateElement(\doc.AppendChild(rootNode); {

XmlElement parentNode = doc.CreateElement(\XmlElement title = doc.CreateElement(\

XmlText strTitle = doc.CreateTextNode(\.NET入门\title.AppendChild(strTitle);

parentNode.AppendChild(title);

XmlElement author = doc.CreateElement(\XmlText txtAuth = doc.CreateTextNode(\张三\author.AppendChild(txtAuth); parentNode.AppendChild(author);

doc.DocumentElement.PrependChild(parentNode); } {

XmlElement parentNode = doc.CreateElement(\XmlElement title = doc.CreateElement(\

XmlText strTitle = doc.CreateTextNode(\.NET精通\title.AppendChild(strTitle);

parentNode.AppendChild(title);

XmlElement author = doc.CreateElement(\

XmlText txtAuth = doc.CreateTextNode(\李四\author.AppendChild(txtAuth); parentNode.AppendChild(author);

doc.DocumentElement.PrependChild(parentNode); }

doc.Save(Server.MapPath(file)); }

void ReadXmlFile(string file) {

//获得文件的物理路径

string xml = Server.MapPath(file);

XmlDocument doc = new XmlDocument(); doc.Load(xml);

XmlNodeList elemList1 = doc.GetElementsByTagName(\for (int i = 0; i < elemList1.Count; i++) {

XmlNode book = elemList1[i];

for (int j = 0; j < book.ChildNodes.Count; j++) {

XmlNode node = book.ChildNodes[j];

Response.Write(\名称:\Response.Write(\作者:\

Response.Write(\} } }

protected void Page_Load(object sender, EventArgs e) {

Response.Write(\开始创建XML文档


\CreateXmlDocument(\

Response.Write(\成功创建Xml文档!\

Response.Write(\读取books.xml文件


\ReadXmlFile(\} }

Chap07参考答案 一、填空题

1. 特定数据源 ASP.NET网页上的其他控件 2. Microsoft SQL Server OLE DB ODBC Oracle 3. Microsoft Access

4. 数据检索 更新功能 高级排序 分页操作 5. 模板 二、选择题

1.ABC 2.ABAB 3.BC 4、A 5、C 三、上机操作题

1.ex7_1.aspx的源代码如下所示: <%@ Page Language=\AutoEventWireup=\Inherits=\

CodeFile=\1.0

Transitional//EN\

根据价格排序

2.ex7_2.aspx的源代码如下: <%@ Page Language=\AutoEventWireup=\Inherits=\

CodeFile=\1.0

Transitional//EN\

根据类型显示作品


ASP NET动态网站开发基础教程习题答案(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2010年下半年中国银行业从业人员资格认证考试--真题&答案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: