All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
剖析SQL Server 2005查询通知之基础篇_[SQL Server教程]
C#教程:使用键盘热键实例
asp.net2.0内置Request对象的应用
Ajax+GridView+Xml的简易留言薄_.net资料_编程技术
ASP.NET(C#)经典采集代码_[Asp.Net教程]
使用ASP.NET,AJAX框架扩展HTML,Map控件_[Asp.Net教程]
故障解决:PHPMyAdmin连接MYSQL的问题_php资料_编程技术
ASP.NET服务器控件之控件状态_[Asp.Net教程]
在Linux下开发.Net程序的环境搭建_[Asp.Net教程]
asp.net2.0控件DataList实例应用
Reading number is top 10 pictures
BingBingFan apple dew point photo gallery1
China's zhejiang university to create the world's most light material
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line
自己约的炮,含泪也要打完
Magnificent cloud1
yy365网站上的美女3
The Soviet union swimsuit exposure in the 70 year2
Sora aoi on twitter3
Absolutely shocked. National geographic 50 animal photographys3
Embarrassing things comic collection2
Download software ranking
Love the forty days
艳兽都市
Boxer's Top ten classic battle6
天龙八部最新服务端
仙剑奇侠传98硬盘WINXP版
Boxer's Top ten classic battle1
天龙八部十二宫服务端
Unix video tutorial1
Tram sex maniac 2 (H) rar bag5
Tram sex maniac 2 (H) rar bag19
aaa published in(发表于) 2013/12/13 9:40:54 Edit(编辑)
C#网络应用编程基础练习题与答案(八)_.net资料_编程技术

C#网络应用编程基础练习题与答案(八)_.net资料_编程技术

C#网络应用编程基础练习题与答案(八)_.net资料_编程技术-你的首页-uuhomepage.com

  1. 使用保持连接的方式编写程序,计算各年级平均成绩,并显示结果。


  【解答】



  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Text;
  using System.Windows.Forms;
  using System.Data.SqlClient;
  namespace 习题8_6_1
  {
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }
  //添加Button按钮在ListBox中显示结果
  private void button1_Click(object sender, EventArgs e)
  {
  listBox1.Items.Add("年级 平均成绩");
  string connectionString = Properties.Settings.Default.MyDatabaseConnectionString;
  //根据连接字符串创建SqlConnection实例
  SqlConnection conn = new SqlConnection(connectionString);
  //创建SqlCommand实例,并设置SQL语句和使用的连接实例
  SqlCommand cmd = new SqlCommand();
  cmd.CommandText = "select substring(学号,1,2) as 年级,avg(成绩) as 平均成绩 from MyTable2 group by substring(学号,1,2)";
  cmd.Connection = conn;
  try
  {
  conn.Open();
  SqlDataReader r = cmd.ExecuteReader();
  while (r.Read() == true)
  {
  listBox1.Items.Add(string.Format("{0}级 {1}", r[0], r[1]));
  }
  r.Close();
  }
  catch (Exception err)
  {
  MessageBox.Show(err.Message, "计算成绩失败");
  }
  finally
  {
  conn.Close();
  }
  }
  }
  }



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.