我们可以从数据库usind SqlTransaction中检索数据吗 [英] Can we retrieve Data from Database usind SqlTransaction

查看:132
本文介绍了我们可以从数据库usind SqlTransaction中检索数据吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



VB.Net2008,SQL Server 2005

感谢您的建议.我的数据库存储在服务器计算机上,客户端正在访问该数据库.我正在做的是检索数据集中的数据.代码如下


Hi,

VB.Net2008, SQL Server 2005

Thankx for your suggestions. My Data Base is stored on a server computer and clients are accessing that db. What i am doing is i retrieve data in a data set. Code is as follows


Protected Function ExecuteDQL(ByVal Query As String) As DataSet
        DS = New DataSet
        DBCom = DBCon.CreateCommand()        
        DBAdp = New SAS.SqlDataAdapter
        Try
            DBCom.CommandText = Query
            DBCom.Connection = DBCon
            DBAdp.SelectCommand = DBCom
            DBAdp.Fill(DS)
            If DS.Tables(0).Rows.Count >= 1 Then
                Return DS
            Else
                Return Nothing
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            CloseDB()
        End Try
    End Function



我感到困惑的是,如果3个用户在同一时间访问相同的数据,而其中一个更改了数据,那么其他2个将处理旧数据,而不是新数据.请在这方面帮助我.

Thankx



What i am confused about is if 3 users access same data in same time and one of those changes data in the meanwhile then other 2 will be dealing with old data rather than the new one. Please Help me in this regard.

Thankx

推荐答案

为什么不可以,为什么要使用?毫无意义!

就Transact-SQL而言,存在三个用于管理事务的重要命令. BEGIN TRANSACTION将开始一个事务,COMMIT TRANSACTION将把该事务提交到数据库,而ROLLBACK TRANSACTION将回滚该事务.

检索数据意味着您正在选择某些东西.选择某些内容时,您不会修改任何数据.因此,没有COMMIT或ROLLBACK角色.

如果您要在事务中插入,更新某些内容,并且还想在它们被插入/更新/删除时检索某些内容,然后进行选择,则意味着事务中有某些内容.

您不需要为此做任何额外的事情.只需在BEGIN&之间插入命令即可结束交易标签,提交或回滚.

希望它清除.

如果需要,请阅读以下内容以获取更多信息:
交易记录SQL示例 [ SqlTransaction类 [ TRY ... CATCH(Transact-SQL) [
why not but why to use? It will have no meaning!

In terms of Transact-SQL, there are three importance commands to manage a transaction. BEGIN TRANSACTION will begin a transaction, COMMIT TRANSACTION will commit the transaction to the database, and ROLLBACK TRANSACTION will roll the transaction back.

Retrieving data means, you are selecting something. When you are selecting something you are NOT MODIFYING any data. Thus, no role of COMMIT or ROLLBACK.

In case, you are inserting, updating something in a transaction and also want to retrieve something the moment they are inserted/updated/deleted then putting a select will mean something in a transaction.

You don''t need to do anything extra for it. Just place your commands in between BEGIN & END tag of transaction, COMMIT it or ROLLBACK.

Hope its clear.

Incase needed, read these for more info:
TRANSACTION SQL Sample[^]
SqlTransaction Class[^]
TRY...CATCH (Transact-SQL)[^]



如果您解释您要做什么,
也许我们可以为您提供帮助.
Hi,
if you explain what are you trying to do ,
maybe we can help you.


这篇关于我们可以从数据库usind SqlTransaction中检索数据吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆