某公司使用ASP.NET+SQLServer开发电子商务网站,该网站分为前台和后台两部分,前台具有会员登录、商品展示、商品搜索、个人中心和购物车等功能;后台具有商品管理、会员管理和订单管理等功能。
【问题1】(6分)
ASP.NET访问数据库一般采用ADO.NET。ADO.NET主要包含Connection对象、Command对象、DataReader对象、DataAdapter对象、DataSet对象和DataView对象等。建立数据源连接使用的对象是 (1) 。连接对象创建完成后,打开连接,需使用的方法是 (2) ,连接对象使用结束后,一般需要关闭连接,使用的方法是 (3) 上。如果在操作数据库时,需要大批量的处理数据或者想在断开数据库连接的情况下操作数据,.NET使用 (4) 对象将数据从数据库服务器中取出,并将数据存入 (5) 对象中。如果要添加、修改或删除数据,需要使用 (6) 对象。
【问题2】(3分)
该电子商务网站数据库business中包含一张新闻表,名为news,结构如表2-1所示。
表2-1 news表结构
现在发现news表中缺少字段“新闻作者”,要求使用SQL语句添加该字段,字段名为newsauthor,数据类型为varchar,长度为20,默认值为admin。请根据题目说明将SQL语句补充完整。
ALTER TABLE (7) ADD (8) (20) default ‘ (9) ’。
【问题3】(6分)
现要设计一个根据关键字搜索新闻及显示搜索结果的页面,页面包含的基本元素为:搜索关键字文本框,控件id为txtKey vord;搜索按钮,控件id为btnSearch;数据绑定显示控件gvNews。请根据题目说明,将空缺的代码补充完整。
protected void btnSearch_Click(coject sender, EventArgs e)
{
string strcon="server='DBServer'; database='business'; uid= 'sa'; pwd='sa';";
SqlConnection con=new SqlConnection(strcon);
string keyword=this (10) ext;
string sqlStr="select * from news where (11) like '%"+keywoed+"%' or (12) like '%"+keywird +"%'";
try
{
SqlDataAdapter da = new SqlDataAdapter( (13) , con);
DataSet ds=new DataSet( ;
da.Fill( (14) );
gvNews. (15) =ds.Tables[)];
gvNews.DataBind();
}
catch
{
Response.Write("无法连接数据库");
}
}
正确答案及解析
正确答案
解析
【问题1】
(1) Connection
(2) Open
(3) Close
(4) DataAdapter
(5) DataSet
(6) Command
【问题2】
(7) news
(8) newsauthor varchar
(9) admin
【问题3】
(10) txtKeyword
(11) newstitli
(12) newscontent
(13) sqIStr
(14) ds
(15) DataSource
注:(11)和(12)答案位置可互换
本题考查数据库SQL语句以及ASP.NET程序设计及应用。
【问题1】
本问题考查ADO.NET对象的使用问题。
ADO.NET包含的对象及其功能如表2-2所示。
表2-2 ADO.NET的对象内容
SqIConnection对象包含的主要属性和方法如表2-3所示。
表2-3 SqlConnection对象主要属性和方法
DataAdapter对象使用Fill方法将采集到的数据填充到数据集DataSet中。
【问题2】
本问题考查SQL语句中修改表结构——添加字段的问题。
修改表结构的SQL语句格式如下:
ALTER TABLE TableName1
ADD | ALTER [COLUMN] FieldName1
FieldType [ (nFieldWidth [, nPrecision]) ]
[NULL | NOT NULL]
[CHECK lExpressionl [ERROR cMessageText1]]
[DEFAULT eExpression1]
[PRIMARY KEY | UNIQUE]
[REFERENCES TableName2 [TAG TagName1]]
[NOCPTRANS]
因此,该题目的SQL语句写法如下:
ALTER TABLE news ADD newsauthor varchar(20) default 'admin'.
【问题3】
本问题考查ASP.NET编程实现模糊搜索。
包含此试题的试卷
你可能感兴趣的试题
Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.
-
- A.Artificial Intelligence
- B.Cloud Computing
- C.Internet of Things
- D.Big Data
- 查看答案
In project human resource management , ( )is not a source of power for the project manager.
-
- A.referent power
- B.expert power
- C.reward power
- D.audit power
- 查看答案
At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.
-
- A.detail feasibility analysis
- B.opportunity analysis
- C.economic feasibility analysis
- D.risk analysis
- 查看答案
( )is a grid that shows the project resources assigned to each work package.
-
- A.Stakeholder engagement assessment matrix
- B.Requirements traceability matrix
- C.Probability and impact matrix
- D.Responsibility assignment matrix
- 查看答案
Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.
-
- A.digital
- B.networking
- C.intelligentize
- D.informatization
- 查看答案