zoukankan      html  css  js  c++  java
  • sqlhelper

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace DAL
     8 {
     9     using System.Configuration;
    10     using System.Data;
    11     using System.Data.SqlClient;
    12      class SQLhelper
    13     {
    14          static readonly string Connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
    15 
    16          public static DataTable ExecuteTable(string sql, CommandType cmdtype, params SqlParameter[] ps)
    17          {
    18              SqlDataAdapter da = new SqlDataAdapter(sql, Connstr);
    19              da.SelectCommand.Parameters.AddRange(ps);
    20              da.SelectCommand.CommandType = cmdtype;
    21              DataTable dt = new DataTable();
    22              da.Fill(dt);
    23              return dt;
    24          }
    25 
    26          public static int ExecNonquery(string sql, CommandType cmdtype, params SqlParameter[] ps)
    27          {
    28              try
    29              {
    30                  using (SqlConnection conn = new SqlConnection(Connstr))
    31                  {
    32                      conn.Open();
    33                      SqlCommand cmd = new SqlCommand(sql, conn);
    34                      cmd.CommandType = cmdtype;
    35                      cmd.Parameters.AddRange(ps);
    36                      return cmd.ExecuteNonQuery();
    37                  }
    38              }
    39              catch (Exception ex)
    40              {
    41                  throw new Exception(ex.Message);
    42              }
    43          }
    44     }
    45 }
  • 相关阅读:
    MySQL学习(一) 概述
    Spring Tool Suite生成默认的MVC项目的配置文件问题
    [国家集训队]排队
    「PKUSC2018」最大前缀和
    「PKUSC2018」真实排名
    Min-Max容斥 & FMT
    SPOJ-CLFLARR 题解
    FFT详解
    CF Round#446 改题
    [CF1131D]Gourmet Choice 题解
  • 原文地址:https://www.cnblogs.com/zhanying/p/4097108.html
Copyright © 2011-2022 走看看