人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

一個數據庫設置類的案例(一.Command類局部)

一個數據庫設置類的案例(一.Command類局部)

更新時間:2022-07-12 文章作者:未知 信息來源:網絡 閱讀次數:

using System;
namespace com.joybase.DB
{
/// <summary>
/// 數據庫操作類,通過這一個類的對外接口,可以獲得以下特性:
/// 1.不必區分數據庫類型,而去考慮是使用System.Data.SqlClient實現,或者使用System.Data.OleDB來實現;
/// 2.可以將SQL語句進行模式化,比如輸入“select * from tablename where username=? order by ? desc",然后再用建模語句將該語句保持完整;
/// 3.數據庫連接實現Connection Pool(該特性是建立在ADO.NET的基礎上的)
/// 4.支持SQL語句的DataReader輸出、無輸出或者DataSet輸出;
/// 5.支持ADO.NET事務級處理;
/// 6.支持存儲過程的輸入及輸出;
/// </summary>
public class Command
{
//最終的SQL語句;
private System.Text.StringBuilder m_SQL;
//中間過程的SQL語句數組
private string[] m_SQLArr;
//替代字符串的數組;
private string[] m_ReplaceText;
//替代字符串的個數;
private int m_Count;
//連接類型;
private System.Data.CommandType m_CommandType;
//在配置文件中用來配置數據庫連接字符串的標簽;
private string m_ConnstringSetName;
/// <summary>
/// 構造方法
/// </summary>
/// <param name="p_sql">模式SQL語句</param>
public Command(string p_sql)
{
 if(p_sql==null) throw new Exception("Error Value");
 if(p_sql.Trim()=="") throw new Exception("Error Value");
 this.m_SQL=new System.Text.StringBuilder();
 m_SQLArr=p_sql.Split('?');
 m_Count=m_SQLArr.Length;
 m_ReplaceText=new string[m_Count-1];
 m_ConnstringSetName="";
 this.m_CommandType=System.Data.CommandType.Text;
}
/// <summary>
/// 在配置文件中用來配置數據庫連接字符串的標簽,如果不設置,則將采用“DataBase.ConnectionString”作為連接字符串使用
/// </summary>
public string ConnStringSetName
{
 set
 {
this.m_ConnstringSetName=value;
 }
}
/// <summary>
/// 所執行命令的類型,即是存儲過程還是普通SQL語句;
/// </summary>
public System.Data.CommandType CommandType
{
 set
 {
this.m_CommandType=value;
 }
}
/// <summary>
/// 以指定的字符串替代在p_loaction位置上的“?”;
/// </summary>
/// <param name="p_location">位置索引</param>
/// <param name="p_InString">欲替代的字符串</param>
public void setString(int p_location,string p_InString)
{
 if(p_InString==null) throw new Exception("Error Value");
 if(p_InString.Trim()==null) throw new Exception("Error Value");
 m_ReplaceText[p_location-1]="'"+p_InString.Trim()+"'";
}
/// <summary>
/// 以指定的整數類型,替代在p_location位置上的"?"
/// </summary>
/// <param name="p_location">位置索引</param>
/// <param name="p_InInt">欲替代的整數</param>
public void setInt(int p_location,int p_InInt)
{
 m_ReplaceText[p_location-1]=p_InInt.ToString();
}
/// <summary>
/// 以指定的長整數類型,替代在p_location位置上的"?"
/// </summary>
/// <param name="p_location">位置索引</param>
/// <param name="p_InLong">欲替代的長整數</param>
public void setLong(int p_location,int p_InLong)
{
 m_ReplaceText[p_location-1]=p_InLong.ToString();
}
/// <summary>
/// 以指定的時間,替代在p_location位置上的"?"
/// </summary>
/// <param name="p_location">位置索引</param>
/// <param name="p_InDateTime">欲替代的時間</param>
public void setDateTime(int p_location,System.DateTime p_InDateTime)
{
 m_ReplaceText[p_location-1]=p_InDateTime.ToString();
}
/// <summary>
/// 以系統時間替代在p_location位置的"?"
/// </summary>
/// <param name="p_location">位置索引</param>
/// <param name="p_OnLyDate">如果為True,則僅替代到日期,如果為False,則替代到時間</param>
public void setDateTime(int p_location,bool p_OnlyDate)
{
 if(p_OnlyDate)
m_ReplaceText[p_location-1]=System.DateTime.Now.Date.ToString();
 else
m_ReplaceText[p_location-1]=System.DateTime.Now.ToString();
}

private string JoinSQLString()
{
 for(int i=0;i<m_Count;i++)
 {
if(i!=0) this.m_SQL.Append(m_ReplaceText[i-1]);
this.m_SQL.Append(m_SQLArr[i]);

 }
 return this.m_SQL.ToString();
}
/// <summary>
/// 執行命令并且返回System.Data.IDataReader結果的結果集
/// </summary>
/// <returns></returns>
public System.Data.IDataReader Result()
{
 System.Data.IDataReader result=null;
 
 try
 {
System.Data.IDbCommand command=Provider.getConn(m_ConnstringSetName).CreateCommand();
command.CommandText=this.JoinSQLString();
command.CommandType=this.m_CommandType;
command.Connection.Close();
command.Connection.Open();
command.Prepare();
//if(Provider.getConn(m_ConnstringSetName).State==System.Data.ConnectionState.Closed)
//Provider.getConn(m_ConnstringSetName).Open();
result=command.ExecuteReader();
//command.Connection.Close();

//Provider.getConn().Close();
 }
 catch
 {
throw new Exception("error at execute db command");
 }
 return result;
}
/// <summary>
/// 無結果執行命令
/// </summary>
public void ExecuteNoResult()
{
 try
 {
System.Data.IDbCommand command=Provider.getConn(m_ConnstringSetName).CreateCommand();
command.CommandText=this.JoinSQLString();
command.CommandType=this.m_CommandType;
command.Connection.Close();
command.Connection.Open();
//if(Provider.getConn(m_ConnstringSetName).State==System.Data.ConnectionState.Closed)
//Provider.getConn(m_ConnstringSetName).Open();
command.ExecuteNonQuery();

 }
 catch
 {
throw new Exception("Error at execute DB Command");
 }
 

}
}
}
 

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 卓资县| 沛县| 涞源县| 迁安市| 湖州市| 十堰市| 长宁区| 广饶县| 武冈市| 新化县| 平利县| 长岛县| 广州市| 定襄县| 昌平区| 山阳县| 安宁市| 长海县| 遂川县| 伽师县| 平果县| 抚州市| 瑞金市| 社旗县| 海宁市| 海南省| 长沙县| 珲春市| 民丰县| 东乌| 淳安县| 澄城县| 吴江市| 韩城市| 大渡口区| 合水县| 运城市| 贡觉县| 青神县| 墨玉县| 云阳县|