⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbhelper.cs

📁 酒店管理系统 用C#开发 程序简单明了 应用系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class DBHelper
    {
        public SqlConnection GetConn()
        {
            SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123456;database=HotelDB");
            return conn;
        }
    }
    public class SQLHelper : DBHelper
    {
        #region ADO.NET组件
        private SqlConnection conn;
        private SqlCommand cmd;
        private SqlDataAdapter sda;
        private DataSet ds;
        #endregion
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sqlString">sqlString</param>
        /// <returns>DataSet</returns>
        public DataSet GetDateSet(string sqlString)
        {
            try
            {
                using (conn = GetConn())
                {
                    using (sda = new SqlDataAdapter(sqlString, conn))
                    {
                        ds = new DataSet();
                        sda.Fill(ds);
                    }
                }
            }
            catch (Exception e)
            {

                throw e;
            }
            return ds;
        }
        /// <summary>
        /// 增.删.改
        /// </summary>
        /// <param name="sqlString">sqlString</param>
        /// <returns>int</returns>
        public int RunSQL(string sqlString)
        {
            int count = 0;
            try
            {
                using (conn = GetConn())
                {
                    conn.Open();
                    using (cmd = new SqlCommand(sqlString, conn))
                    {
                        count = cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                
                throw e;
            }
            return count;
        }
    }
}

⌨️ 快捷键说明

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