标题:请大家帮忙看看这段代码哪里有问题,谢谢!
取消只看楼主
杀虫剂
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-12-12
 问题点数:0 回复次数:1 
请大家帮忙看看这段代码哪里有问题,谢谢!
Shared Function Insert(ByVal ConnectionString As String, ByVal SQLString As String) As Integer
        Dim Connection As SqlConnection = New SqlConnection(ConnectionString)
        Dim Command As SqlCommand = New SqlCommand(SQLString, Connection)
        Dim Transaction As SqlTransaction
        Dim Count As Integer = 0

        Connection.Open()
        Transaction = Connection.BeginTransaction()
        Command.Transaction = Transaction

        Try
            Count = Command.ExecuteNonQuery()
            ()
        Catch ex As SqlException
            MsgBox(ex.ToString())
        Catch ex As Exception
            MsgBox(ex.ToString())
        Finally
            Connection.Close()
        End Try
        Return Count
    End Function

学习VB2005中
调用insert后count的返回值说明数据库操作正常,但就是没有添加进数据.
可我的代码里有commit呀
传进的参数为SQLString = "INSERT INTO Table1(aaa,bbb,ccc) VALUES('a2','b2','c2')"
自己研究好几天了,不知道哪里错了.
谢谢了!!!
搜索更多相关主题的帖子: Transaction Connection Dim Command 代码 
2007-12-12 16:24
杀虫剂
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-12-12
得分:0 
还是不行
不行呀!试了.
2007-12-13 08:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-192077-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.592090 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved