基于SQL Server 的Exception Handling - PART II
2008-12-06 10:15:28 来源:WEB开发网· Delete Data: P_CLEAR_DATA
CREATE Procedure P_CLEAR_DATA
AS
DELETE FROM dbo.T_USERS_IN_ROLES
DELETE FROM dbo.T_USERS
DELETE FROM dbo.T_ROLES
GO
4. Common Function:Utility. ExecuteCommand
private const string connectionStringName = "TestDb";
public static bool ExecuteCommand(string procedureName, Dictionary<string, object> parameters)
{
ConnectionStringSettings connectionStringSection = ConfigurationManager.ConnectionStrings[connectionStringName];
DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory(connectionStringSection.ProviderName);
using (DbConnection connection = dbProviderFactory.CreateConnection())
{
connection.ConnectionString = connectionStringSection.ConnectionString;
connection.Open();
DbCommand command = connection.CreateCommand();
command.CommandText = procedureName;
command.CommandType = CommandType.StoredProcedure;
DbParameter parameter;
foreach (KeyValuePair<string, object> param in parameters)
{
parameter = dbProviderFactory.CreateParameter();
parameter.ParameterName = param.Key;
parameter.DbType = DbType.String;
parameter.Value = param.Value;
command.Parameters.Add(parameter);
}
DbTransaction transation = connection.BeginTransaction();
command.Transaction = transation;
try
{
command.ExecuteNonQuery();
transation.Commit();
return true;
}
catch
{
transation.Rollback();
throw;
}
}
}
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››基于IP地址的vsftp服务器
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接