where Studentslh.学生学号lh=@学生学号lh end
Sql执行结果如下:
6、应用系统开发与试运行
6.1 开发平台和开发环境介绍
开发平台:Microsoft Visual Studio 2010
开发环境:
Visual Studio是微软公司推出的开发环境。是目前最流行的Windows平台应用程序开发环境。Visual Studio 2010版本于2010年4月12日上市,其集成开发环境(IDE)的界面被重新设计和组织,变得更加简单明了。Visual Studio 2010同时带来了 NET Framework 4.0、Microsoft Visual Studio 2010 CTP( Community Technology Preview--CTP),并且支持开发面向Windows 7的应用程序。除了Microsoft SQL Server,它还支持 IBM DB2和Oracle数据库。
与此同时,微软还引入了一门新的语言C#,C#是一门建立在C++和Java基础上的编写.NET框架的现代语言。
我的数据库是在Microsoft Visual Studio 2010平台上以C#语言开发的。
6.2 系统功能图
(1)创建功能窗体
26
(2)链接数据库 C#代码:
using System;
using System.Collections.Generic; using System.Linq; using System.Text; using System.Data;
using System.Data.SqlClient; using System.Windows.Forms;
namespace C01luhai {
class sqlConnect {
public SqlConnection coon = null; public sqlConnect() {
if (coon == null) {
coon = new SqlConnection(\ + \Catalog =C01luhai\);
if (coon.State == ConnectionState.Closed) coon.Open(); } }
public void closeConnect() {
if (coon.State == ConnectionState.Open) coon.Close(); }
public DataSet Getds(string sql) {
if (coon.State == ConnectionState.Closed) coon.Open(); DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, coon);
da.Fill(ds); coon.Close(); return ds; }
public int OperateData(string sql) {
if (coon.State == ConnectionState.Closed) coon.Open(); SqlCommand sqlcom = new SqlCommand(); sqlcom.CommandText = sql;
sqlcom.CommandType = CommandType.Text; sqlcom.Connection = coon;
27
int x = sqlcom.ExecuteNonQuery(); coon.Close(); return x; }
public DataSet BinDataGriView(DataGridView dgv, string sql) {
if (coon.State == ConnectionState.Closed) coon.Open(); SqlDataAdapter da = new SqlDataAdapter(sql, coon); DataSet ds = new DataSet(); da.Fill(ds);
dgv.DataSource = ds.Tables[0]; return ds; } } }
截图:
(3)登录窗口: C#代码:
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System.Windows.Forms;
namespace C01luhai
28
{
public partial class frmLogin : Form {
public frmLogin() {
InitializeComponent(); }
private void btnLogin_Click(object sender, EventArgs e) {
if(txtName.Text == \ || txtPwd.Text == \)
MessageBox.Show(\用??户?ì名?或¨°密¨1码?不?能¨1为a空?!ê?\,\提?¨¢示o?\,MessageBoxButtons.OK,MessageBoxIcon.Information); else {
frmMain fmain = new frmMain(); fmain.Show(); this.Hide(); } }
private void btnExit_Click(object sender, EventArgs e) {
this.Dispose(); } } }
截图:
29
(5) 主窗口: C#代码:
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System.Windows.Forms;
namespace C01luhai {
public partial class frmMain : Form {
public frmMain() {
InitializeComponent(); }
private void 退a?出?ToolStripMenuItem_Click_1(object sender, EventArgs e) {
Application.Exit(); }
private void 学?ì生|¨2成¨|绩?§统a3计?ToolStripMenuItem_Click(object sender, EventArgs e) {
frmReport1 fReport1 = new frmReport1(); fReport1.Show(); }
private void 学?ì生|¨2成¨|绩?§名?次??排?定?§ToolStripMenuItem_Click(object sender, EventArgs e) {
frmReport2 fReport2 = new frmReport2(); fReport2.Show(); }
private void 每?门?课?平?均¨′成¨|绩?§统a3计?ToolStripMenuItem_Click(object sender, EventArgs e) {
frmReport3 fReport3 = new frmReport3(); fReport3.Show(); }
30