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. C#
  4. Byte Conversion

Byte Conversion

Scheduled Pinned Locked Moved C#
help
11 Posts 5 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.
  • S Offline
    S Offline
    spankyleo123
    wrote on last edited by
    #1

    Hi ppl, I have a table with two column ID (tinyint) and TEXT (varchar). I am using this table to populate the droplist on my windows form. when i select items from the droplist I am getting this error "ByteConverter cannot convert from System.Int32." NotSupportedException was unhandled. I am populating the selected ID of the droplist into the main table. Pls help. thanks,

    realJSOPR 1 Reply Last reply
    0
    • S spankyleo123

      Hi ppl, I have a table with two column ID (tinyint) and TEXT (varchar). I am using this table to populate the droplist on my windows form. when i select items from the droplist I am getting this error "ByteConverter cannot convert from System.Int32." NotSupportedException was unhandled. I am populating the selected ID of the droplist into the main table. Pls help. thanks,

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      show us the code that's handling the selection of the droplist item...

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      S 1 Reply Last reply
      0
      • realJSOPR realJSOP

        show us the code that's handling the selection of the droplist item...

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        S Offline
        S Offline
        spankyleo123
        wrote on last edited by
        #3

        combobox.datasource = data.tbtest;
        combobox.DisplayMember = "Text";
        comboBox.ValueMember = "ID";

        This code populates the combobox droplist. and the user selects the appropriate value and the selectedvalue ID gets stored into the Form Table on Button click. Just to add on (on Button Click)

        table.TestID = Convert.ToByte(comboBox.Selectedvalue)

        I hope this makes sense.

        T 1 Reply Last reply
        0
        • S spankyleo123

          combobox.datasource = data.tbtest;
          combobox.DisplayMember = "Text";
          comboBox.ValueMember = "ID";

          This code populates the combobox droplist. and the user selects the appropriate value and the selectedvalue ID gets stored into the Form Table on Button click. Just to add on (on Button Click)

          table.TestID = Convert.ToByte(comboBox.Selectedvalue)

          I hope this makes sense.

          T Offline
          T Offline
          The Man from U N C L E
          wrote on last edited by
          #4

          I'm not clear why you are converting it to a byte, however ... SelectedValue is of type Object and so you will be calling the Convert.ToByte overload that takes Object, which MUST implement IConvertible. Int32 does not implement this interface. The solution is to force it to an int first . e.g.

          table.TestID = Convert.ToByte((int)comboBox.Selectedvalue)

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

          L S 3 Replies Last reply
          0
          • T The Man from U N C L E

            I'm not clear why you are converting it to a byte, however ... SelectedValue is of type Object and so you will be calling the Convert.ToByte overload that takes Object, which MUST implement IConvertible. Int32 does not implement this interface. The solution is to force it to an int first . e.g.

            table.TestID = Convert.ToByte((int)comboBox.Selectedvalue)

            If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Are you sure? http://msdn.microsoft.com/en-us/library/system.int32.aspx[^] Also, int and System.Int32 are just two different way of writing the same thing

            T 1 Reply Last reply
            0
            • T The Man from U N C L E

              I'm not clear why you are converting it to a byte, however ... SelectedValue is of type Object and so you will be calling the Convert.ToByte overload that takes Object, which MUST implement IConvertible. Int32 does not implement this interface. The solution is to force it to an int first . e.g.

              table.TestID = Convert.ToByte((int)comboBox.Selectedvalue)

              If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

              S Offline
              S Offline
              spankyleo123
              wrote on last edited by
              #6

              Sorry mate. By CType do u mean Conversion.ChangeType in C#? Could you provide the same in C# please. I am converting it to Byte because the column in of type tinyint (8 bit integer = 1 byte) Thanks,

              1 Reply Last reply
              0
              • T The Man from U N C L E

                I'm not clear why you are converting it to a byte, however ... SelectedValue is of type Object and so you will be calling the Convert.ToByte overload that takes Object, which MUST implement IConvertible. Int32 does not implement this interface. The solution is to force it to an int first . e.g.

                table.TestID = Convert.ToByte((int)comboBox.Selectedvalue)

                If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

                S Offline
                S Offline
                spankyleo123
                wrote on last edited by
                #7

                Thanks for the answer. When i select an item from the combobox and tab to the next control... its giving me the same exception. Do I have to change any property of the combobox? Cheers!!

                S 1 Reply Last reply
                0
                • S spankyleo123

                  Thanks for the answer. When i select an item from the combobox and tab to the next control... its giving me the same exception. Do I have to change any property of the combobox? Cheers!!

                  S Offline
                  S Offline
                  Saksida Bojan
                  wrote on last edited by
                  #8

                  spankyleo123 wrote:

                  . When i select an item from the combobox and tab to the next control... its giving me the same exception

                  What excepiton? Where it does happen, and in witch event?

                  S 1 Reply Last reply
                  0
                  • S Saksida Bojan

                    spankyleo123 wrote:

                    . When i select an item from the combobox and tab to the next control... its giving me the same exception

                    What excepiton? Where it does happen, and in witch event?

                    S Offline
                    S Offline
                    spankyleo123
                    wrote on last edited by
                    #9

                    Its this one ... "ByteConverter cannot convert from System.Int32." NotSupportedException was unhandled. This happens when i select a combobox item and go to next control on the form. Many thanks,

                    L 1 Reply Last reply
                    0
                    • S spankyleo123

                      Its this one ... "ByteConverter cannot convert from System.Int32." NotSupportedException was unhandled. This happens when i select a combobox item and go to next control on the form. Many thanks,

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      This thread seems to be getting lost. Try stepping through the code in the debugger (put a breakpoint where the exception occurs), and capture all values. Then post those values, the exception, and the code around the exception, so people can see everything that is involved with the problem in one message.

                      txtspeak is the realm of 9 year old children, not developers. Christian Graus

                      1 Reply Last reply
                      0
                      • L Lost User

                        Are you sure? http://msdn.microsoft.com/en-us/library/system.int32.aspx[^] Also, int and System.Int32 are just two different way of writing the same thing

                        T Offline
                        T Offline
                        The Man from U N C L E
                        wrote on last edited by
                        #11

                        Thanks, I stand corrected. I checked as far as it is a structure and missed the interface declaration.

                        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

                        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