zoukankan      html  css  js  c++  java
  • SqlHelper

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    
    
    namespace LZJ_Common
    {
        public class SqlHelper
        {
            private static readonly string ConStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
    
            /// <summary>
            /// 增删改方法
            /// </summary>
            /// <param name="sqlstr"></param>
            /// <param name="psm"></param>
            public int ExeCuteNonQuery(string sqlstr, params SqlParameter[] psm)
            {
                using (SqlConnection mycon = new SqlConnection(ConStr))
                {
                    using (SqlCommand mycom = new SqlCommand(sqlstr, mycon))
                    {
                        if (psm != null)
                        {
                            mycom.Parameters.AddRange(psm);
                        }
                        mycon.Open();
                        return mycom.ExecuteNonQuery();
                    }
                }
            }
    
            public object ExeCuteSclar(string sqlstr, params SqlParameter[] psm)
            {
                using (SqlConnection mycon = new SqlConnection(ConStr))
                {
                    using (SqlCommand mycom = new SqlCommand(sqlstr, mycon))
                    {
                        if (psm != null)
                        {
                            mycom.Parameters.AddRange(psm);
                        }
                        mycon.Open();
                        return mycom.ExecuteScalar();
                    }
                }
            }
    
            public SqlDataReader ExeCuteReader(string sqlstr, params SqlParameter[] psm)
            {
                SqlConnection mycon = new SqlConnection(ConStr);
                using (SqlCommand mycom = new SqlCommand(sqlstr, mycon))
                {
                    if (psm != null)
                    {
                        mycom.Parameters.AddRange(psm);
                    }
    
                    try
                    {
                        mycon.Open();
                        return mycom.ExecuteReader(CommandBehavior.CloseConnection);
                    }
                    catch (Exception ex)
                    {
                        mycon.Dispose();
                        throw ex;
                    }
                }
            }
    
            public DataTable ExeCuteDataTable(string sqlstr, params SqlParameter[] psm)
            {
                DataTable dt = new DataTable();
                using (SqlDataAdapter myda = new SqlDataAdapter(sqlstr, ConStr))
                {
                    if (psm != null)
                    {
                        myda.SelectCommand.Parameters.AddRange(psm);
                    }
                    myda.Fill(dt);
                    return dt;
                }
            }
    
    
    
        }
    }
    
  • 相关阅读:
    Java AJAX开发系列 5,ZK参考资料
    现代浏览器客户端Web开发 Project Silk
    Java AJAX开发系列 2,项目中使用ZK
    Java性能分析点滴
    Java AJAX开发系列 4,ZK应用实例
    Java AJAX开发系列 3, ZK MVC
    大型网站如何架构 网页资料集
    Google Analytics 进行网站流量分析
    ALM TFS/VSTS工具 的Java集成
    系统各层关注的内容【DDDD笔记】
  • 原文地址:https://www.cnblogs.com/lierjie/p/3791863.html
Copyright © 2011-2022 走看看