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 }
  • 相关阅读:
    冒泡 希尔 快速 插入 堆 基数
    排序总结
    软件工程(齐治昌-谭庆平-宁洪)
    Java简单计算器
    插入排序
    Android中theme.xml与style.xml的区别
    activity theme parent 属性浅析
    xml中不能直接添加ViewGroup
    Java中对象的上转型对象
    Android原理View、ViewGroup
  • 原文地址:https://www.cnblogs.com/zhanying/p/4097108.html
Copyright © 2011-2022 走看看