2012下C#试卷(含答案) 联系客服

发布时间 : 星期二 文章2012下C#试卷(含答案)更新完毕开始阅读

string logs = \

if (________________________)//如果文件不存在 { File.Create(logs).Close(); } string logstxt = File.ReadAllText(logs); logstxt += \ File.WriteAllText(logs, logstxt);

得 分 评卷 人 五、程序设计题(共10分)

已知SQL数据库student中定义了一张person表,表的数据结构如下: 字段名称字段类型字段含义

字段名 类型 说明 Id 数字 编号 Xm 文本 姓名 Xb 文本 性别 Nl 数字 年龄 Zip 文本 邮政编码 用编写代码的方法在DataGridView中显示该数据表中年龄大于18且性别为“男”的所有纪录,显示时以编号的升序排序。

计分点:1、数据库连接(3分);2、构造正确的查询表达式(2分);3、使用ADO.net的SqlDataAdapter,DataSet对象,将数据存入DataTable对象中(3分);4、将数据绑定到DataGridView(2分)

共10页 第9页 共10页 第10页

参考答案

一、选择题(每小题2分,共30分) DataSet ds = new DataSet();(1分) sda.Fill(ds); (1分) DataTable dt = ds.Tables[\dataGridView1.DataSource = dt.DefaultView; (2分) 题号 1 2 3 4 5 6 7 8 9 10

答案 A A A D D C D D C B 题号 11 12 13 14 15 答案 D A D B A

二、填空题(每小题2分,共30分) 1、Main/Main() 2、cw 3、object 4、接口类型 5、装箱 6、6 7、公共语言运行时/CLR 8、MyCmd.Visible 9、多态 10、4 11、类名/类 12、base 13、override 14、interface 15、返回影响的记录行数

三、程序阅读题(每小题3分,共15分) 1、死循环

2、10

四、程序填空题(每小题3分,共15分)

1、委托应用:delegate void EatDelegate(string s); //声明委托

2、数据库的连接:con.Open();

3、索引指示器的定义this[int index] //索引指示器的定义 4、“打开文件”对话框:opf.ShowDialog() 5、文件操作:!File.Exists(logs)

五、程序设计题(共10分) 参考代码:

string strCon = @\(1分) SqlConnection con = new SqlConnection(strCon); (1分) con.Open();(1分) string strSQL = \性别='男' and 年龄=18\(2分) SqlDataAdapter sda = new SqlDataAdapter(strSQL, con); (1分) 共10页 第11页 共10页 第12页