那位哥们有C#Db2连接数据库的代码,最好封装的好的,计较通用,谢谢
能实现查询,更新,删除
xglhm@sh163.net
谢谢!
------解决方案--------------------/// <summary>
/// 返回对数据库只读流操作
/// </summary>
/// <param name="sSql">SQL语句</param>
/// <returns></returns>
internal SqlDataReader sreadclose(string sSql)
{
SqlCommand Com = new SqlCommand();
Com.CommandText = sSql;
if (WholeObj.Conn.State.ToString() == "Closed")
WholeObj.Conn.Open();
Com.Connection = WholeObj.Conn;
SqlDataReader rsread = Com.ExecuteReader();
Com.Dispose();
WholeObj.Conn.Close();
return rsread;
}
/// <summary>
/// 返回对数据库只读流操作
/// </summary>
/// <param name="sSql">SQL语句</param>
/// <returns></returns>
internal System.Data.SqlClient.SqlDataReader sread(string sSql)
{
System.Data.SqlClient.SqlCommand Com = new SqlCommand();
try
{
Com.CommandText = sSql;
Com.Connection = WholeObj.Conn;
if (WholeObj.Conn.State.ToString() == "Closed")
WholeObj.Conn.Open();
System.Data.SqlClient.SqlDataReader rsread = Com.ExecuteReader();
Com.Dispose();
return rsread;
}
catch (Exception)
{
WholeObj.Conn.Open();
System.Data.SqlClient.SqlDataReader rsread = Com.ExecuteReader();
Com.Dispose();
return rsread;
}
}
/// <summary>
/// 返回数据在内存中的缓存填充
/// </summary>
/// <param name="sSql">SQL语句</param>
/// <param name="tbn">用于表映射的源表名称</param>
/// <returns></returns>
internal System.Data.DataSet sqldataset(string sSql, string tbn)
{
System.Data.SqlClient.SqlDataAdapter getdata;
if (WholeObj.Conn.State.ToString() == "Closed")
WholeObj.Conn.Open();
getdata = new SqlDataAdapter(sSql.Trim(), WholeObj.Conn);
System.Data.DataSet sj = new System.Data.DataSet();
getdata.Fill(sj, tbn.Trim());
getdata.Dispose();
return sj;
}
/// <summary>
/// 返回数据在内存中的缓存填充
/// </summary>
/// <param name="sSql">SQL语句</param>
/// <returns></returns>
internal System.Data.DataSet sqldataset(string sSql)
{
System.Data.SqlClient.SqlDataAdapter getdata;
try
{
if (WholeObj.Conn.State.ToString() == "Closed")
WholeObj.Conn.Open();
getdata = new SqlDataAdapter(sSql.Trim(), WholeObj.Conn);
System.Data.DataSet sj = new System.Data.DataSet();
getdata.Fill(sj, "sj");
getdata.Dispose();
return sj;
}
catch (Exception)
{
if (WholeObj.Conn.State.ToString() == "Closed")
WholeObj.Conn.Open();
getdata = new SqlDataAdapter(sSql.Trim(), WholeObj.Conn);
System.Data.DataSet sj = new System.Data.DataSet();
getdata.Fill(sj, "sj&q