using system;using system.text;
using system.data;
using system.data.common;
namespace data.core
}/// /// 關聯式資料庫連線字串
///
public static string connectionstring
}#if debug
private static int _executecount = 0;
private static string _executedetail = string.empty;
/// /// 資料庫執行次數
///
public static int executecount
set
}/// /// 資料庫執行細節
///
public static string executedetail
set
}/// /// 設定資料庫執行細節
///
/// 資料庫執行語句
/// 資料庫執行開始時間
/// 資料庫執行結束時間
/// 資料庫執行引數列表
///
private static string getexecutedetail(string commandtext, datetime starttime, datetime endtime, dbparameter commandparameters)
").tostring();
}return string.empty;
}#endif
static rdbshelper()
#region db transaction
public static void begintransaction()
else
}public static void committransaction()
else
}public static void rollbacktransaction()
else
}private static void releasetransaction()
private static void openconnection(dbconnection conn)
if (conn.state == connectionstate.closed)
}private static void closeconnection(dbconnection conn)
conn.dispose();
conn = null;
}#endregion
#region executenonquery
public static int executenonquery(string cmdtext)
public static int executenonquery(commandtype cmdtype, string cmdtext)
public static int executenonquery(commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
}public static int executenonquery(dbtransaction trans, commandtype cmdtype, string cmdtext)
public static int executenonquery(dbtransaction trans, commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
#endregion
#region executenoquerytrans
public static int executenonquerytrans(string cmdtext)
public static int executenonquerytrans(commandtype cmdtype, string cmdtext)
public static int executenonquerytrans(string cmdtext, params dbparameter commandparameters)
public static int executenonquerytrans(commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
catch (dbexception)
finally
}return val;
}#endregion
#region executereader
public static dbdatareader executereader(commandtype cmdtype, string cmdtext)
public static dbdatareader executereader(commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
catch
conn.close();
throw;}}
public static dbdatareader executereader(dbtransaction trans, commandtype cmdtype, string cmdtext)
public static dbdatareader executereader(dbtransaction trans, commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
#endregion
#region executescalar
public static object executescalar(commandtype cmdtype, string cmdtext)
public static object executescalar(commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
}public static object executescalar(dbtransaction trans, commandtype cmdtype, string cmdtext)
public static object executescalar(dbtransaction trans, commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
#endregion
#region executedataset
public static dataset executedataset(commandtype cmdtype, string cmdtext)
public static dataset executedataset(commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
catch
finally
}public static dataset executedataset(dbtransaction trans, commandtype cmdtype, string cmdtext)
public static dataset executedataset(dbtransaction trans, commandtype cmdtype, string cmdtext, params dbparameter commandparameters)
#endregion
private static void preparecommand(dbcommand cmd, dbconnection conn, dbtransaction trans, commandtype cmdtype, string cmdtext, dbparameter cmdparms)
else
else
}cmd.commandtype = cmdtype;
if (cmdparms != null)
cmd.parameters.add(parm);}}
}}
}// 事務處理類
internal class transconnection
public dbtransaction dbtransaction
public int deeps
}}
Sql Server資料庫幫助類
using system using system.collections.generic using system.linq using system.web using system.data.sqlclient using system.data using system.configurat...
Sql Server 資料庫幫助類
注 資料庫操作幫助封裝類,簡單易用,減少 冗餘 資料庫鏈結 也可配置在web.config 檔案中 public static readonly string connectionstring server 資料庫鏈結 uid 賬號 pwd 密碼 database 資料庫名 執行乙個不需要返回值的s...
資料庫幫助類
新建乙個類庫,專門來處理資料。我覺得這個和ef的思想是差不多的,等有時間我好好研究一下ef,以後就不再用自己寫sql了 public class sqlhelper string sql select from table sqlcommand com new sqlcommand sql,conn...