none
sql语句批量更新数据库所有表,执行不正常 RRS feed

  • 问题

  • 1、我使用以下语句给每一个表添加列是成功的。
      Public Function FIXTable(ByVal TBLname As String) As String
            Using connection As New SqlClient.SqlConnection(cs)
                connection.Open()
                'Dim sqlstr As String = "Alter table " + TBLname + " add 定额编号 VARCHAR(25)"
                Dim cmd As New SqlClient.SqlCommand(sqlstr, connection)
                Try
                   cmd.ExecuteNonQuery()
                Catch ex As Exception
                End Try
            End Using
            Return 0
        End Function
    2、但我将SQL语句更改为插入、删除语句,然后查看数据库却发现没有被更改,程序没有报任何错误。
      Public Function FIXTable(ByVal TBLname As String) As String
            Using connection As New SqlClient.SqlConnection(cs)
                connection.Open()
                            ' Dim sqlstr As String = "update " + TBLname + " set '定额编号' =" + TBLname + "where '电算号'<>0"
                Dim sqlstr As String = "del from  " + TBLname + "  where  '电算号'  <> " & 0
                           Dim cmd As New SqlClient.SqlCommand(sqlstr, connection)
                Try
                    ' cmd.ExecuteNonQuery()
                    cmd.ExecuteScalar()
                Catch ex As Exception
                End Try
            End Using
            Return 0
        End Function


    http://hi.baidu.com/useek/blog

    2012年4月17日 8:03

答案