Results 1 to 3 of 3

Thread: [RESOLVED] Data truncated for column 'columnname' at row 1

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2018
    Posts
    46

    Resolved [RESOLVED] Data truncated for column 'columnname' at row 1

    Hello,


    I am using MySQL database connected to Visual Studio 2017 Community Edition. I have a checkbox and textboxes on a Winform VB.Net. In my MySQL database, the datatype of the Status checkbox is ENUM('T','F'). I have some vb.net code to update changes in the form.

    The vb.net code is:

    Code:
    Private Sub UpdateStatus(Optional messages As Boolean = True)
      Dim query = "UPDATE Plans Set Status = @status, PlanNotes = @plannotes " &
                "WHERE PLANID = @planId"
    con = New MySqlConnection("Server=localhost;Port=3306;Database=mydatabase;userid=root;password=mypassword;persist security info=True")
            con.Open()
            cmd = New MySqlCommand(query, con)
    
    cmd.Parameters.AddWithValue("@status", Me.ChkStatus.Checked)
    cmd.Parameters.AddWithValue("@plannotes", Me.txtPlanNotes.Text)
    cmd.Parameters.AddWithValue("@planId", Me.txtPlanID.Text)
    
            cmd.ExecuteNonQuery()
            con.Close()
    
        End Sub
    If I try to input any changes in the data fields and press the Update button, an error message is thrown at the line: cmd.ExecuteNonQuery() as follows: -

    Code:
    MySql.Data.MySqlClient.MySqlException: 'Data truncated for column 'Status' at row 1'

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Data truncated for column 'columnname' at row 1

    If the database field stores text, you should pass the appropriate text - rather than a number or boolean etc.

    That may be as simple as:
    Code:
    Dim statusText as String = If(Me.ChkStatus.Checked, "T","F")
    cmd.Parameters.AddWithValue("@status", statusText)

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2018
    Posts
    46

    Re: Data truncated for column 'columnname' at row 1

    Hi si_the_geek,

    Your solution worked perfectly! Thank you very much.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width