5 Replies - 324 Views - Last Post: 21 March 2019 - 03:28 PM Rate Topic: -----

#1 wire_jp   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 10-January 19

Data truncated for column 'columnname' at row 1

Posted 21 March 2019 - 07:51 AM

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:

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: -

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


Is This A Good Question/Topic? 0
  • +

Replies To: Data truncated for column 'columnname' at row 1

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6775
  • View blog
  • Posts: 27,938
  • Joined: 12-December 12

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

Posted 21 March 2019 - 08:01 AM

ChkStatus.Checked is a boolean true/false value. It won't automatically morph into a string 'T' or 'F'. You need to perform that change.

If status is only a true/false value then why not use a bit or boolean MySql data type?
Was This Post Helpful? 1
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14925
  • View blog
  • Posts: 59,590
  • Joined: 12-June 08

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

Posted 21 March 2019 - 08:03 AM

Any particular reason the true/false check field isn't a bit? 0 or 1..
Was This Post Helpful? 0
  • +
  • -

#4 wire_jp   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 10-January 19

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

Posted 21 March 2019 - 11:19 AM

no specific reason for using true/false check field. I will switch to bit. Thanks.
Was This Post Helpful? 0
  • +
  • -

#5 DarenR   User is offline

  • D.I.C Lover

Reputation: 601
  • View blog
  • Posts: 3,932
  • Joined: 12-January 10

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

Posted 21 March 2019 - 12:35 PM

i dont know about others but i always code my true or false fields as bit

0 and 1
Was This Post Helpful? 1
  • +
  • -

#6 wire_jp   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 10-January 19

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

Posted 21 March 2019 - 03:28 PM

ok, thank you for the information.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1