一周又过去了,一周的编码任务却没有完。下周就要彻底的结束这令人难受的项目了,这次的时间确实是有些紧了。不过充足的时间却浪费在了漫长的设计阶段了。
最近感觉很烦,一点都不想去公司了,每天想着一去公司就要面对那令人心烦的项目就没心情上班了。这破玩意既浪费时间又学不到啥东西,真的很令人伤心啊。
每天无聊的code and code没一点新鲜感。在那项目上没有遇到什么难题,也不会有什么难点。o(︶︿︶)o 唉,只好拿这来凑凑字数了。
//该类用于取得web.config中配置的数据库连接字符串
public class PubConstant
{
/// <summary>
/// 获取连接字符串
/// </summary>
public static string ConnectionString
{
get
{
//string _connectionString1 = ConfigurationManager.ConnectionStrings[];
string _connectionString = ConfigurationManager.AppSettings["ConnectionString"];
string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
if (ConStringEncrypt == "true")
{
_connectionString = DESEncrypt.Decrypt(_connectionString);
}
return _connectionString;
}
}
/// <summary>
/// 得到web.config里配置项的数据库连接字符串。
/// </summary>
/// <param name="configName"></param>
/// <returns></returns>
public static string GetConnectionString(string configName)
{
string connectionString = ConfigurationManager.AppSettings[configName];
string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
if (ConStringEncrypt == "true")
{
connectionString = DESEncrypt.Decrypt(connectionString);
}
return connectionString;
}
}
取得连接字符串后,执行sql语句,
/// <summary>
/// 执行查询语句,返回DataSet
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataSet</returns>
public static DataSet Query(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
/// <summary>
/// 根据连接字符串,执行查询语句,qing7-15
/// </summary>
/// <param name="SQLString">sql语句</param>
/// <param name="connString">数据库连接字符串</param>
/// <returns>查询数据集</returns>
public static DataSet Query(string SQLString, string connString)
{
string connectionString2 = PubConstant.GetConnectionString(connString);
using (SqlConnection connection = new SqlConnection(connectionString2))
{
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
这里需要用到不同服务器上的数据库,只好将在web.config里配置的连接字符串的connectionString名传进来了以便确定要查询的数据库。
字数差不多了,就此打住,O(∩_∩)O~