Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. String or binary data would be truncated. The statement has been terminated

String or binary data would be truncated. The statement has been terminated

Scheduled Pinned Locked Moved Visual Basic
helpdatabase
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zaimah
    wrote on last edited by
    #1

    b4 this my prgm running ok.. and i don't do any editing. after a few days, when i try to add data in my databse, there was a msg "runtime error" about my web.config.. my customErrors mode="off", so i change my mode to RemoteOnly.. but another problem come out. it says that "String or binary data would be truncated. The statement has been terminated" and then the source error is : Line 623: cmd.Connection.Open() Line 624: cmd.ExecuteNonQuery() <-- this line r in red colour Line 625: cmd.Connection.Close() this happen after i key in my data and i want to add the data to my database... helpp me pls...

    C D Z 3 Replies Last reply
    0
    • Z zaimah

      b4 this my prgm running ok.. and i don't do any editing. after a few days, when i try to add data in my databse, there was a msg "runtime error" about my web.config.. my customErrors mode="off", so i change my mode to RemoteOnly.. but another problem come out. it says that "String or binary data would be truncated. The statement has been terminated" and then the source error is : Line 623: cmd.Connection.Open() Line 624: cmd.ExecuteNonQuery() <-- this line r in red colour Line 625: cmd.Connection.Close() this happen after i key in my data and i want to add the data to my database... helpp me pls...

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I'm sorry, but that's not really all that helpful. This tells me that: 1 - you want to run some SQL 2 - if it ran some data somewhere would be truncated 3 - it throws an error I can't tell you more than that, and I'd hope you could work that out for yourself. I'd say this means one of your parameters is too big, which in turn makes me syspect that you're string mashing SQL, which probably means your code is open to all sorts of attacks. But, hard to say if you are not showing the pertinent code.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • Z zaimah

        b4 this my prgm running ok.. and i don't do any editing. after a few days, when i try to add data in my databse, there was a msg "runtime error" about my web.config.. my customErrors mode="off", so i change my mode to RemoteOnly.. but another problem come out. it says that "String or binary data would be truncated. The statement has been terminated" and then the source error is : Line 623: cmd.Connection.Open() Line 624: cmd.ExecuteNonQuery() <-- this line r in red colour Line 625: cmd.Connection.Close() this happen after i key in my data and i want to add the data to my database... helpp me pls...

        D Offline
        D Offline
        darkelv
        wrote on last edited by
        #3

        First Hit from google[^]

        1 Reply Last reply
        0
        • Z zaimah

          b4 this my prgm running ok.. and i don't do any editing. after a few days, when i try to add data in my databse, there was a msg "runtime error" about my web.config.. my customErrors mode="off", so i change my mode to RemoteOnly.. but another problem come out. it says that "String or binary data would be truncated. The statement has been terminated" and then the source error is : Line 623: cmd.Connection.Open() Line 624: cmd.ExecuteNonQuery() <-- this line r in red colour Line 625: cmd.Connection.Close() this happen after i key in my data and i want to add the data to my database... helpp me pls...

          Z Offline
          Z Offline
          zaimah
          wrote on last edited by
          #4

          this is my coding. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim _kod As String Dim Pemanggil As String Dim Negeri As String Dim run_no As String Pemanggil = TextBox10.Text.Trim Negeri = TextBox4.Text.Trim If Kod.Text.Length > 0 And Nama.Text.Length > 0 And TextBox4.Text.Length > 0 And TextBox10.Text.Length > 0 And No_Tel.Text.Length > 0 And Masalah.Text.Length > 0 And Penyelesaian.Text.Length > 0 And TextBox9.Text.Length > 0 Then Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("strConn")) Dim MySQL As String = "INSERT INTO Senarai_Log(docNo,Tarikh,Kod_Koop,Nama_Koop,Nama_Koop1,Negeri,Nama,No_Tel,Masalah,Penyelesaian,Tindakan) Values (@docNo,@Tarikh,@Kod_Koop,@Nama_Koop,@Nama_Koop1,@Negeri,@Nama,@No_Tel,@Masalah,@Penyelesaian,@Tindakan)" Dim cmd As SqlCommand = New SqlCommand(MySQL, myConn) cmd.Parameters.Add(New SqlParameter("@Tarikh", SqlDbType.NVarChar, 250)) cmd.Parameters("@Tarikh").Value = System.DateTime.Now.Date cmd.Parameters.Add(New SqlParameter("@Kod_Koop", SqlDbType.NVarChar, 250)) cmd.Parameters("@Kod_Koop").Value = Kod.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama_Koop", SqlDbType.NVarChar, 250)) cmd.Parameters("@Nama_Koop").Value = Nama.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama_Koop1", SqlDbType.NVarChar, 250)) cmd.Parameters("@Nama_Koop1").Value = Nama1.Text.Trim cmd.Parameters.Add(New SqlParameter("@Negeri", SqlDbType.NVarChar, 250)) cmd.Parameters("@Negeri").Value = Negeri cmd.Parameters.Add(New SqlParameter("@No_Tel", SqlDbType.Char, 50)) cmd.Parameters("@No_Tel").Value = No_Tel.Text.Trim cmd.Parameters.Add(New SqlParameter("@Masalah", SqlDbType.Char, 250)) cmd.Parameters("@Masalah").Value = Masalah.Text.Trim cmd.Parameters.Add(New SqlParameter("@Penyelesaian", SqlDbType.NVarChar, 250)) cmd.Parameters("@Penyelesaian").Value = Penyelesaian.Text.Trim cmd.Parameters.Add(New SqlParameter("@Tindakan", SqlDbType.Char, 50)) cmd.Parameters("@Tindakan").Value = TextBox9.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama", SqlDbType.Char, 50)) cmd.Parameters("@Nama").Value = Peman

          A C 2 Replies Last reply
          0
          • Z zaimah

            this is my coding. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim _kod As String Dim Pemanggil As String Dim Negeri As String Dim run_no As String Pemanggil = TextBox10.Text.Trim Negeri = TextBox4.Text.Trim If Kod.Text.Length > 0 And Nama.Text.Length > 0 And TextBox4.Text.Length > 0 And TextBox10.Text.Length > 0 And No_Tel.Text.Length > 0 And Masalah.Text.Length > 0 And Penyelesaian.Text.Length > 0 And TextBox9.Text.Length > 0 Then Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("strConn")) Dim MySQL As String = "INSERT INTO Senarai_Log(docNo,Tarikh,Kod_Koop,Nama_Koop,Nama_Koop1,Negeri,Nama,No_Tel,Masalah,Penyelesaian,Tindakan) Values (@docNo,@Tarikh,@Kod_Koop,@Nama_Koop,@Nama_Koop1,@Negeri,@Nama,@No_Tel,@Masalah,@Penyelesaian,@Tindakan)" Dim cmd As SqlCommand = New SqlCommand(MySQL, myConn) cmd.Parameters.Add(New SqlParameter("@Tarikh", SqlDbType.NVarChar, 250)) cmd.Parameters("@Tarikh").Value = System.DateTime.Now.Date cmd.Parameters.Add(New SqlParameter("@Kod_Koop", SqlDbType.NVarChar, 250)) cmd.Parameters("@Kod_Koop").Value = Kod.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama_Koop", SqlDbType.NVarChar, 250)) cmd.Parameters("@Nama_Koop").Value = Nama.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama_Koop1", SqlDbType.NVarChar, 250)) cmd.Parameters("@Nama_Koop1").Value = Nama1.Text.Trim cmd.Parameters.Add(New SqlParameter("@Negeri", SqlDbType.NVarChar, 250)) cmd.Parameters("@Negeri").Value = Negeri cmd.Parameters.Add(New SqlParameter("@No_Tel", SqlDbType.Char, 50)) cmd.Parameters("@No_Tel").Value = No_Tel.Text.Trim cmd.Parameters.Add(New SqlParameter("@Masalah", SqlDbType.Char, 250)) cmd.Parameters("@Masalah").Value = Masalah.Text.Trim cmd.Parameters.Add(New SqlParameter("@Penyelesaian", SqlDbType.NVarChar, 250)) cmd.Parameters("@Penyelesaian").Value = Penyelesaian.Text.Trim cmd.Parameters.Add(New SqlParameter("@Tindakan", SqlDbType.Char, 50)) cmd.Parameters("@Tindakan").Value = TextBox9.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama", SqlDbType.Char, 50)) cmd.Parameters("@Nama").Value = Peman

            A Offline
            A Offline
            Ashfield
            wrote on last edited by
            #5

            Check the lengths of the parameters/ values against the corresponding database columns. Thats usually the problem, data longer than the column supports.

            Bob Ashfield Consultants Ltd

            1 Reply Last reply
            0
            • Z zaimah

              this is my coding. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim _kod As String Dim Pemanggil As String Dim Negeri As String Dim run_no As String Pemanggil = TextBox10.Text.Trim Negeri = TextBox4.Text.Trim If Kod.Text.Length > 0 And Nama.Text.Length > 0 And TextBox4.Text.Length > 0 And TextBox10.Text.Length > 0 And No_Tel.Text.Length > 0 And Masalah.Text.Length > 0 And Penyelesaian.Text.Length > 0 And TextBox9.Text.Length > 0 Then Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("strConn")) Dim MySQL As String = "INSERT INTO Senarai_Log(docNo,Tarikh,Kod_Koop,Nama_Koop,Nama_Koop1,Negeri,Nama,No_Tel,Masalah,Penyelesaian,Tindakan) Values (@docNo,@Tarikh,@Kod_Koop,@Nama_Koop,@Nama_Koop1,@Negeri,@Nama,@No_Tel,@Masalah,@Penyelesaian,@Tindakan)" Dim cmd As SqlCommand = New SqlCommand(MySQL, myConn) cmd.Parameters.Add(New SqlParameter("@Tarikh", SqlDbType.NVarChar, 250)) cmd.Parameters("@Tarikh").Value = System.DateTime.Now.Date cmd.Parameters.Add(New SqlParameter("@Kod_Koop", SqlDbType.NVarChar, 250)) cmd.Parameters("@Kod_Koop").Value = Kod.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama_Koop", SqlDbType.NVarChar, 250)) cmd.Parameters("@Nama_Koop").Value = Nama.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama_Koop1", SqlDbType.NVarChar, 250)) cmd.Parameters("@Nama_Koop1").Value = Nama1.Text.Trim cmd.Parameters.Add(New SqlParameter("@Negeri", SqlDbType.NVarChar, 250)) cmd.Parameters("@Negeri").Value = Negeri cmd.Parameters.Add(New SqlParameter("@No_Tel", SqlDbType.Char, 50)) cmd.Parameters("@No_Tel").Value = No_Tel.Text.Trim cmd.Parameters.Add(New SqlParameter("@Masalah", SqlDbType.Char, 250)) cmd.Parameters("@Masalah").Value = Masalah.Text.Trim cmd.Parameters.Add(New SqlParameter("@Penyelesaian", SqlDbType.NVarChar, 250)) cmd.Parameters("@Penyelesaian").Value = Penyelesaian.Text.Trim cmd.Parameters.Add(New SqlParameter("@Tindakan", SqlDbType.Char, 50)) cmd.Parameters("@Tindakan").Value = TextBox9.Text.Trim cmd.Parameters.Add(New SqlParameter("@Nama", SqlDbType.Char, 50)) cmd.Parameters("@Nama").Value = Peman

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              I never specify lengths like this, I just add the parameters directly and let the framework, work it out for me. I would suggest that it would be great for you to do some study, you may want to read the article I link to in my sig, it explains how best to get help when you have an error message you cannot understand.

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              Z 1 Reply Last reply
              0
              • C Christian Graus

                I never specify lengths like this, I just add the parameters directly and let the framework, work it out for me. I would suggest that it would be great for you to do some study, you may want to read the article I link to in my sig, it explains how best to get help when you have an error message you cannot understand.

                Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                Z Offline
                Z Offline
                zaimah
                wrote on last edited by
                #7

                thank you. i have found the problem. the article really help.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups