高校學生資訊管理系統C#窗體版更新(一)

weixin_33766168發表於2017-11-15

首先給大家介紹基本的窗體構架,前期給大家說說學計算機比較需要學習的地方 - 資料庫,給大家寫了一個大學裡導師教導,自己總結出來的資料庫連結的類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,如需轉載請自行聯絡原作者

相關文章