using
System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Reflection;
/**/ /// <summary>
/// DBClass : SQL Server 数据库 操作类
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// xx. YYYY/MM/DD VER AUTHOR COMMENTS
/// 1. 2008/03/04 Free CREATE
/// </history>
public class DBClass
{
SqlConnection theSqlConnection = new SqlConnection();
得到数据库连接字串#region 得到数据库连接字串
static public string DBConnString()
{
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
return strConn;
}
#endregion
运行Select查询 得到一个DataSet#region 运行Select查询 得到一个DataSet
public static DataSet RunSelectGetDataSet(string strSelect)
{
DataSet ds = new DataSet();
using (SqlConnection sqlConn = new SqlConnection(DBClass.DBConnString()))
{
sqlConn.Open();
SqlDataAdapter da = new SqlDataAdapter(strSelect, sqlConn);
da.Fill(ds);
sqlConn.Close();
}
return ds;
}
#endregion
运行查询 得到DataTable#region 运行查询 得到DataTable
public static DataTable RunSelectGetDataTable(string strSelect)
{
DataTable dt = new DataTable();
using (SqlConnection sqlConn = new SqlConnection(DBClass.DBConnString()))
{
sqlConn.Open();
SqlDataAdapter da = new SqlDataAdapter(strSelect, sqlConn);
da.Fill(dt);
sqlConn.Close();
}
return dt;
}
#endregion
运行非Select的Insert或Update或Delete语句 成功返回true 否则返回false#region 运行非Select的Insert或Update或Delete语句 成功返回true 否则返回false
/**//// <summary>
/// 运行非Select的Insert或Update或Delete语句 成功返回true 否则返回false
/// </summary>
/// <param name="strCommand">Insert或Update或Delete语句</param>
/// <returns>成功返回true 否则返回false</returns>
public static Boolean RunNotSelectSqlCommand(string strCommand)
{
try
{
using (SqlConnection sqlConn = new SqlConnection(DBClass.DBConnString()))
{
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand(strCommand, sqlConn);
sqlComm.ExecuteNonQuery();
sqlConn.Close();
}
return true;
}
catch (Exception ex)
{
return false;
}
}
#endregion
}
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Reflection;
/**/ /// <summary>
/// DBClass : SQL Server 数据库 操作类
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// xx. YYYY/MM/DD VER AUTHOR COMMENTS
/// 1. 2008/03/04 Free CREATE
/// </history>
public class DBClass
{
SqlConnection theSqlConnection = new SqlConnection();
得到数据库连接字串#region 得到数据库连接字串
static public string DBConnString()
{
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
return strConn;
}
#endregion
运行Select查询 得到一个DataSet#region 运行Select查询 得到一个DataSet
public static DataSet RunSelectGetDataSet(string strSelect)
{
DataSet ds = new DataSet();
using (SqlConnection sqlConn = new SqlConnection(DBClass.DBConnString()))
{
sqlConn.Open();
SqlDataAdapter da = new SqlDataAdapter(strSelect, sqlConn);
da.Fill(ds);
sqlConn.Close();
}
return ds;
}
#endregion
运行查询 得到DataTable#region 运行查询 得到DataTable
public static DataTable RunSelectGetDataTable(string strSelect)
{
DataTable dt = new DataTable();
using (SqlConnection sqlConn = new SqlConnection(DBClass.DBConnString()))
{
sqlConn.Open();
SqlDataAdapter da = new SqlDataAdapter(strSelect, sqlConn);
da.Fill(dt);
sqlConn.Close();
}
return dt;
}
#endregion
运行非Select的Insert或Update或Delete语句 成功返回true 否则返回false#region 运行非Select的Insert或Update或Delete语句 成功返回true 否则返回false
/**//// <summary>
/// 运行非Select的Insert或Update或Delete语句 成功返回true 否则返回false
/// </summary>
/// <param name="strCommand">Insert或Update或Delete语句</param>
/// <returns>成功返回true 否则返回false</returns>
public static Boolean RunNotSelectSqlCommand(string strCommand)
{
try
{
using (SqlConnection sqlConn = new SqlConnection(DBClass.DBConnString()))
{
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand(strCommand, sqlConn);
sqlComm.ExecuteNonQuery();
sqlConn.Close();
}
return true;
}
catch (Exception ex)
{
return false;
}
}
#endregion
}