zoukankan      html  css  js  c++  java
  • SqlDbHelper的封装

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Model;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    
    namespace DAL
    {
        public class DBHelper
        {
    
           // static string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
    
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=four;Integrated Security=True");
    
            //增删改
            public int ExeNonQuery(string sql)
            { 
                //打开数据库
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql,conn);
                int i = cmd.ExecuteNonQuery();
                conn.Close();
                return i;
            }
    
            //聚合函数查询
            public object ExeScalar(string sql)
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                object i = cmd.ExecuteScalar();
                conn.Close();
                return i;  
            }
    
            //多条数据
            public DataTable GetTable(string sql)
            {
                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                return dt;
            
            }
    
    
        }
    }
  • 相关阅读:
    Python 集合
    Python 文字列
    JUNIT5(maven配置)
    Javascript严格模式
    移动互联测试
    Python的基础知识
    Linux系统下发件oa环境
    禅道的使用
    Linux系统的安装过程
    Oracle基础知识
  • 原文地址:https://www.cnblogs.com/gbb44/p/10639110.html
Copyright © 2011-2022 走看看