Byte Conversion
-
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,
-
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,
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 -
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, 2001combobox.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.
-
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.
I'm not clear why you are converting it to a byte, however ... SelectedValue is of type
Object
and so you will be calling theConvert.ToByte
overload that takesObject
, which MUST implementIConvertible
.Int32
does not implement this interface. The solution is to force it to anint
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]
-
I'm not clear why you are converting it to a byte, however ... SelectedValue is of type
Object
and so you will be calling theConvert.ToByte
overload that takesObject
, which MUST implementIConvertible
.Int32
does not implement this interface. The solution is to force it to anint
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]
-
I'm not clear why you are converting it to a byte, however ... SelectedValue is of type
Object
and so you will be calling theConvert.ToByte
overload that takesObject
, which MUST implementIConvertible
.Int32
does not implement this interface. The solution is to force it to anint
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]
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,
-
I'm not clear why you are converting it to a byte, however ... SelectedValue is of type
Object
and so you will be calling theConvert.ToByte
overload that takesObject
, which MUST implementIConvertible
.Int32
does not implement this interface. The solution is to force it to anint
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]
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!!
-
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!!
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?
-
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?
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,
-
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,
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
-
Are you sure? http://msdn.microsoft.com/en-us/library/system.int32.aspx[^] Also,
int
andSystem.Int32
are just two different way of writing the same thingThanks, 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]