高校学生信息管理系统C#窗体版更新(一)

首先给大家介绍基本的窗体构架,前期给大家说说学计算机比较需要学习的地方 - 数据库,给大家写了一个大学里导师教导,自己总结出来的数据库链接的类DataAccess.cs代码:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
namespace StudentsScore
{
    class DataAccess
    {
        private string strDSN;
        OleDbConnection oledbCon;
        //数据库连接方法
        public void dataCon()
        {
            strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.
                StartupPath.ToString() + "\\student.mdb";
            oledbCon = new OleDbConnection(strDSN);
        }
        //获取 DataSet
        public DataSet getDataset(string sql)
        {
            DataSet ds = new DataSet();
            oledbCon.Open();
            try
            {
                OleDbCommand oledbCom = new OleDbCommand(sql, oledbCon);
                OleDbDataAdapter oledbDa = new OleDbDataAdapter(oledbCom);
                oledbDa.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                oledbCon.Close();
            }
        }
        //执行SQl语句
        public bool sqlExec(string sql)
        {
            try
            {
                oledbCon.Open();
            }
            catch
            {
                MessageBox.Show("数据库未连接");
            }
            try
            {
                OleDbCommand oledbCom = new OleDbCommand(sql, oledbCon);
                oledbCom.ExecuteNonQuery();
                return true;
            }
            catch 
            {
                MessageBox.Show("必须先删除成绩的信息!", "提示");
                return false;
            }
            finally
            {
                oledbCon.Close();
            }

        }
    }
}
 

今天临时有些事情,今后还会继续更新..谢谢大家!一起交流学习吧!










本文转自 吴雨声 51CTO博客,原文链接:http://blog.51cto.com/liangxiao/709583,如需转载请自行联系原作者
上一篇:阿里云域名查询、域名注册、域名实名认证和域名备案全过程


下一篇:服务启动报错