晚上好,
我正在使用以下代码截断 MySQL 数据库中的表。据我所知,查询运行良好,表被截断。但是,我用来测试行是否受到影响的 if 语句正在 Else 语句上进行评估。
那么为什么数据库中的表被截断 - 正如预期的那样 - 但 Else 语句正在被评估 - 好像没有行受到影响?我究竟做错了什么?
这是代码:
Public Sub purgeCC()
Dim dbAdapter As New MySqlDataAdapter
Dim dbCmd As New MySqlCommand
Dim ConnectionString As String = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
Dim myQuery As String = "TRUNCATE TABLE cc_master"
Using dbConn As New MySqlConnection(ConnectionString)
Using dbComm As New MySqlCommand()
With dbComm
.Connection = dbConn
.CommandType = CommandType.Text
.CommandText = myQuery
End With
Try
Dim affectedRow As Integer
dbConn.Open()
affectedRow = dbComm.ExecuteNonQuery()
If affectedRow > 0 Then
MsgBox("Credit Card Master table has been successfully purged!", MsgBoxStyle.Information, "DATABASE PURGED!")
Else
MsgBox("Credit Card Master table was not purged!", MsgBoxStyle.Critical, "ATTENTION")
End If
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
dbConn.Close()
dbComm.Dispose()
End Using
End Using
End Sub