这个方法怎样用???方法如下:
/// <summary>
/// 执行查询
/// </summary>
/// <param name="sqlCommand"></param>
public int ExecuteNonQuery(IDbCommand sqlCommand)问题:参数是IDbCommand,怎样用呢?
{
if(TransactionContext.Current!=null) //需要执行事务
{
try
{
if(TransactionContext.Current.DbTransaction!=null)
{
sqlCommand.Connection=TransactionContext.Current.DbTransaction.Connection;
sqlCommand.Transaction=TransactionContext.Current.DbTransaction;
}
return TransactionContext.Current.Provider.Database.ExecuteNonQuery(sqlCommand);
}
catch(Exception ex)
{
TransactionContext.Current.Rollback();
throw new Exception(ex.Message);
}
}
else //不需要事务
{
return _provider.Database.ExecuteNonQuery(sqlCommand);
}
}
/// <summary>
/// 执行查询
/// </summary>
/// <param name="sqlCommand"></param>
public int ExecuteNonQuery(IDbCommand sqlCommand)问题:参数是IDbCommand,怎样用呢?
{
if(TransactionContext.Current!=null) //需要执行事务
{
try
{
if(TransactionContext.Current.DbTransaction!=null)
{
sqlCommand.Connection=TransactionContext.Current.DbTransaction.Connection;
sqlCommand.Transaction=TransactionContext.Current.DbTransaction;
}
return TransactionContext.Current.Provider.Database.ExecuteNonQuery(sqlCommand);
}
catch(Exception ex)
{
TransactionContext.Current.Rollback();
throw new Exception(ex.Message);
}
}
else //不需要事务
{
return _provider.Database.ExecuteNonQuery(sqlCommand);
}
}
解决方案 »
- 我想学asp.net 应该从哪几个方面入手!
- 推荐一本适合算法初学者的算法入门书吧
- 求一条SQL语句
- 如何对dataset做一下过滤操作?
- 超重量级的问题~~~~见者有分!!!!!!!!!!!!!
- aspx頁面提交到aspx頁面為何出錯?
- 微软提供的ASP.NET Reports源代码,单独分出来不行啊
- 怎么老要我注册ASPNET_REGIIS -C?我已经注册过了!
- 两个数据源绑定同一个DATAGRID控件如何分页?
- 在页面中写哪些HTML可以告诉搜索引擎当前页面是PC版还是手机版?
- web应用程序
- httpcontext.Response.Write或WriteFile如何输出网上的图片??
return _provider.Database.ExecuteNonQuery(sqlCommand);就直接输入一个insert into table values.....这样的SQL语句 传入进去用事务控制