成都网站建设设计

将想法与焦点和您一起共享

DBOperate.cs-创新互联

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

我们提供的服务有:成都网站建设、网站设计、微信公众号开发、网站优化、网站认证、肃宁ssl等。为上千多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的肃宁网站制作公司

///


///DBOperate 的摘要说明
///

public class DBOperate
{
    private static SqlConnection con = null;
    private static SqlCommand cmd = null;
    private static SqlDataAdapter da = null;
   // private static SqlDataReader dr = null;
    public static SqlConnection createCon()
    {
        string constr = ConfigurationManager.AppSettings["server"];
        //string constr = ConfigurationManager.ConnectionStrings["connection"].ToString();
        con = new SqlConnection(constr);
        return con;
    }
    public static int execSQL(string sql)
    {
        int rows;
        try
        {
            con = createCon();
            if (con.State != ConnectionState.Open)
                con.Open();

            cmd = new SqlCommand(sql, con);
            rows= cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception e)
        {
            throw new Exception(e.Message, e);
        }
        finally
        {
            if (con.State == ConnectionState.Open)
                con.Close();
        }
        return rows;

    }

   public static DataSet getDataSet(string sql, string table)
    {
        try
        {
            con = createCon();
            da = new SqlDataAdapter(sql, con);
            DataSet ds = new DataSet();
            da.Fill(ds, table);
            return ds;
        }
        catch (Exception e)
        {
            throw new Exception(e.Message, e);
        }
    }
    public static SqlDataReader getReader(string sql)
    {
        try
        {
            con = createCon();
            if (con.State != ConnectionState.Open)
                con.Open();
            cmd = new SqlCommand(sql, con);
            return cmd.ExecuteReader();
        }
        catch (Exception e)
        {
            throw new Exception(e.Message, e);
        }
    }
}

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


分享名称:DBOperate.cs-创新互联
本文链接:http://chengdu.cdxwcx.cn/article/disjje.html