using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
成都創(chuàng)新互聯(lián)是一家專注于網(wǎng)站制作、網(wǎng)站建設(shè)與策劃設(shè)計,東港網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:東港等地區(qū)。東港做網(wǎng)站價格咨詢:18980820575
///
///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);
}
}
}