operator.cs

来自「这是一个图书馆管理用的简化系统」· CS 代码 · 共 99 行

CS
99
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace BMS
{
    class Operator
    {
        //通用的SELECT功能
        public static DataSet SelectSql(string sqlSelect)
        {
            SqlConnection con = DB.getcon();
            SqlDataAdapter sda = new SqlDataAdapter(sqlSelect, con);
            DataSet ds = new DataSet();
            try
            {
                sda.Fill(ds);
            }
            catch (SqlException e)
            {
                throw new Exception(e.Message);
            }
            return ds;
        }
        //通用的对数据进行添加,修改,删除的功能
        public static int ExecuteSql(string sql)
        {
            int rows = -1;
            SqlConnection con = DB.getcon();
            SqlCommand cmd = new SqlCommand(sql, con);
            try
            {
                con.Open();
                string str = con.State.ToString();
                rows = cmd.ExecuteNonQuery();
            }
            catch (SqlException e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                cmd.Dispose();
                con.Close();
            }
            return rows;
        }
        //将选择的值读到指定的文本框中去
        public static SqlDataReader fill(string strSQL)
        {
            SqlConnection con = DB.getcon();
            SqlCommand cmd = new SqlCommand(strSQL, con);
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            return reader;
        }
        //通用返回行数的功能
        public static int select(string strSQL)
        {
            int rows = -1;
            SqlConnection con = DB.getcon();
            SqlCommand cmd = new SqlCommand(strSQL, con);
            try
            {
                con.Open();
                rows = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (SqlException e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                cmd.Dispose();
                con.Close();
            }
            return rows;
        }
        public static DataTable Datafill(string sqlSelect)//DataSet SelectSql
        {
            SqlConnection con = DB.getcon();
            SqlDataAdapter sda = new SqlDataAdapter(sqlSelect, con);
            DataTable ds = new DataTable();
            try
            {
                sda.Fill(ds);
            }
            catch (SqlException e)
            {
                throw new Exception(e.Message);
            }
            return ds;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?