易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET和SQL SERVER中使用事务示例

1,SqlServer存储过程的事务处理
一种比较通用的出错处理的模式大概如下:
Create procdure prInsertProducts
(
 @intProductId int,
 @chvProductName varchar(30),
 @intProductCount int
)
AS
Declare @intErrorCode int
Select @intErrorCode=@@Error
Begin transaction
 if @intErrorCode=0
   begin
     -insert products
     insert products(ProductID,ProductName,ProductCount)
     s(@intProductId,@chvProductName,@intProductCount)
     Select @intErrorCode=@@Error --每执行完一条t-sql语句马上进行检测,并把错误号保存到局部变量中
   end
 if @intErrorCode=0
   begin
     -update products
     update products set ProductName='MicroComputer' where ProductID=5
     Select @intErrorCode=@@Error
   end
if @intErrorCode=0
   commit transaction
else
   rollback transaction
 Return @intErrorCode --最好返回错误代号给调用的存储过程或应用程序
2,.Net中使用事务处理
SqlConnection myConnection = new SqlConnection("Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;");
myConnection.Open();
SqlTransaction myTrans = myConnection***ginTransaction(); //使用New新生成一个事务
SqlCommand myCommand = new SqlCommand();
myCommand.Transaction = myTrans;
try
{
myCommand.CommandText = "Update Address set location='23 rain street' where userid='0001'";
myCommand.ExecuteNonQuery();
myTrans.Commit();
Console.WriteLine("Record is udated.");
}
catch(Exception e)
{
myTrans.Rollback();
Console.WriteLine(e.ToString());
Console.WriteLine("Sorry, Record can not be updated.");
}
finally
{
myConnection.Close();
}


相关文档:

SQL Server CLR全功略之三

本节主要介绍使用CLR创建标量函数,表值函数和聚合函数。
所谓标量函数指的就是此函数只返回一个值。表值函数返回值是一个表。聚合函数是在select语句中使用的,用来聚合一个结果集,类似于Sum()或是Count()等内置的函数,而且真正的自定义聚合函数目前只能用CLR来实现。
下面的例子使用了SQLServer自带的pubs数据库。
1 ......

【转】SQL 优化

from: http://www.javaeye.com/topic/498902?page=1 
最近从朋友那看了一个某咨询公司给一家企业做的一个优化项目的总结报告书,其历时两个月,10万费用,4个人。
最终结果是性能和相应提升了30%,总共修改了3行代码和配置,共修改了3个单词,不到20个字母~~~~。
朋友总结了一句话,就是“代码质量越烂的项目 ......

SQL 2008 怎样还原数据库?

因现在的工作需要,
我得从WinForm的平台,
转型到WebForm的页面。
有一年多没有接触SQL Server了,
虽然大学时有点基础,
但也忘记得差不多了。
因为Asp.net型的B/S网站和WinForm的还是有点不同,
现在工作起来不是那么得心应手。
温故而知新,
就把以前实习时做的的网站源代码拿出来看看。
因为要用到SQL 2005S ......

ASP.NET中FCKeditor_2.6.3配置

FCKeditor介绍
  FCKeditor是一个功能强大支持所见即所得功能的文本编辑器,可以为用户提供微软office软件一样的在线文档编辑服务。它不需要安装任何形式的客户端,兼容绝大多数主流浏览器,支持ASP.Net、ASP、ColdFusion 、PHP、Java、Active-FoxPro、Lasso、Perl、ython 等编程环境。
  官方网站http://www.fckedit ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号