Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:12:55+00:00 2026-06-14T06:12:55+00:00

Good evening, I’m using the following code to truncate a table in my MySQL

  • 0

Good evening,

I’m using the following code to truncate a table in my MySQL database. From what I can tell, the query is running fine and the tables are being truncated. However, the if statement that I’m using to test if rows are affected is being evaluated on the Else statement.

So how come the table in the database is being truncated – as expected – but the Else statement is being evaluated – as if no rows are affected? What am I doing wrong?

HERE’S THE CODE:

    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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:12:57+00:00Added an answer on June 14, 2026 at 6:12 am

    Per this document http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html
    the truncate command may not always return the rows affected if the DB version is greater than 5.somthing and the table does not have foreign key constraints. if you do have FKs then a delete is processed for each row and you get the return value you are seeking, but if you don’t then mysql will drop and re-add the table (which is much faster), which means it has no ideas how many records were affected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening everyone, I am using a JavaScript to load/override content from an HTML-File
Good evening, Following is the code I used for reading the files and folders
Good evening, I wrote the code below in C to read and print from
Good Evening, I can't seem to get my code to only add one instance
Good evening, I'm having an issue with Masonry. This is all my relevant code:
Good evening, experts I want to solve recurrence equation using mathematica, x(n) = x(n
Good evening, i hope you can help me with this problem, as I'm struggling
Good evening, I made a well working function with php, mysql and ajax. A
Good Evening StackOverflowers! I am running into what seems to be a catch 22
Good Evening, I'm using Drupal 6, CCK Module, and the Link Field Type. All

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.