当前位置:首页 > 学生管理系统实习报告模板
图4.3.5 修改信息窗口
图4.3.6 删除信息提示
图4.3.7 添加信息窗口
11
第五章 主要功能模块代码
5.1 公共类代码设计
namespace MySql {
public class mySql {
public String connectionString = @\学习\\C#\\课程设计\\StuScoreManSystem\\StuScoreManSystem\\StuScoManSys.mdf;
Integrated Security=True;Connect Timeout=30;User Instance=True;\ public String commondText;
public bool flag; //指示有条该条记录 public System.Data.DataView table;
public void runSql() // 执行查询、删除SQL语句 {
using (SqlConnection connection = new SqlConnection(connectionString)) {
connection.Open();
SqlCommand cmdQuery = new SqlCommand(commondText, connection);
SqlDataAdapter sda = new SqlDataAdapter(commondText, connection); DataSet ds = new DataSet(); sda.Fill(ds);
if (commondText.IndexOf(\ {
table = ds.Tables[0].DefaultView; }
connection.Close(); } }
public bool getFlag() //判断是否有该条记录 {
using (SqlConnection connection = new SqlConnection(connectionString)) {
connection.Open();
SqlCommand cmdQuery = new SqlCommand(commondText,
12
connection);
SqlDataReader reader = cmdQuery.ExecuteReader(); if (reader.Read()) flag = true; else flag = false; reader.Close(); connection.Close(); return flag; } }
public String getContent(String require,String SNO) //获取视图表的的指定单元格内容
{
try {
commondText = \学号=\
if (require == \课程名称\
commondText = \课程名称 FROM detail WHERE 学号=\
if (require == \成绩\
commondText = \成绩 FROM detail WHERE 学号=\SNO;
SqlDataAdapter sda = new SqlDataAdapter(commondText, connectionString);
DataSet ds = new DataSet(); sda.Fill(ds); String result=\
if(require==\课程名称\成绩\ {
int i=new int();
for (i=0; i result = result+ds.Tables[0].Rows[i][require].ToString()+\ } } else result=ds.Tables[0].Rows[0][require].ToString().Trim(); return result; } catch { return \无\ } 13 } public void update() {//添加、更新语句 try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmdInsert = new SqlCommand(commondText, connection); cmdInsert.ExecuteNonQuery(); connection.Close(); } } catch(Exception ex) { MessageBox.Show(ex.ToString(), \提示\ } } } } 5.2 登录界面代码设计 private void login_Click(object sender, EventArgs e) {//用户名及密码组合判断 if (username.Text.ToString().Trim() != \&& password.Text.ToString().Trim() != \ { mySql sql = new mySql(); sql.commondText = %username.Text.ToString().Trim() + \\ try { bool temp = new bool(); temp = sql.getFlag(); if (temp) 14
共分享92篇相关文档