I have a MySQL Table, one of the columns' Data Type is TinyInt(1)
When I use this line of code it gives an error
int newNumber = int.Parse(string.Format("{0}", reader["someField"])
I think the reader is reading a bool value
however MySQL Table has row values of 0 & 1 & 6 & 7
so it is not bool true/false type
How can I actually grab that value to store into "int newNumber"
Thanks
Sam HobbsPosted Feb 10, 2014, 4:20 PM
Tell you what, Severus. Try taking your own advice. Try providing some actual useful help. Can you do that?
Severus SnapesPosted Feb 10, 2014, 3:51 PM
theLizardPosted Aug 16, 2011, 1:46 AM
Sam HobbsPosted Aug 16, 2011, 1:22 AM
If we are going to continue to discuss it, then can you please try doing what I requested?
David ChenPosted Aug 16, 2011, 1:13 AM
since its TinyInt(1), a bool value, so its either 0, False or 1~9, True
but if you add +0 it will convert to the int value
theLizardPosted Aug 16, 2011, 1:09 AM
David ChenPosted Aug 16, 2011, 1:01 AM
theLizardPosted Aug 15, 2011, 9:22 PM
30 or 40 years ago memory and storage were at a premium so doing what David is doing would have been a valid reason but today memory and storage is not that much of a premium and you can easily afford to use a small int.
My question for David is what reason are you using TinyInt for other than true or false? If you want to use a TinyInt for a 3 state check box then I can understand that but in this case you can have values 0, 1, 2, 2 being the third state why are you wanting to store 3,4,5,6,7,8, & 9!!
If I know that I will not be storing values > 9 I use an int or even a varchar in some cases but this depends on what I am doing with it.
Seems to me that by using TinyInt he is now working around a problem he would NOT have by using small int or int, my suggestion is convert the MySql field to an INT and be done with it..
Sam HobbsPosted Aug 15, 2011, 5:53 PM
VulpesPosted Aug 15, 2011, 3:46 PM
Sam HobbsPosted Aug 15, 2011, 3:11 PM
Vulpes, note that in the first reply I said that there is a duplicate. What more can we do? I usually add a link to the other thread but that is extra work. The problem is that theLizard did not see that reply either and replied to this thread. Could you other guys please explain to David that we don't appreciate people creating duplicate threads?
VulpesPosted Aug 15, 2011, 2:38 PM
David ChenPosted Aug 15, 2011, 2:21 PM
string sql = "SELECT (newNumber+0) AS abcd FROM tblSomeTable WHERE id = '29954' LIMIT 1";
int newNumber = Convert.ToInt32(reader["abcd"]);
Console.WriteLine(newNumber);
print out 6
problem has to do with the select statement by adding " (newNumber+0)" then everything is ok
VulpesPosted Aug 15, 2011, 2:09 PM
Sam HobbsPosted Aug 15, 2011, 1:10 PM
I sure wish that David tried my last suggestion. Then he would know for sure what the C# data type is and then use that as the cast.
VulpesPosted Aug 15, 2011, 12:07 PM
VulpesPosted Aug 15, 2011, 7:00 AM
theLizardPosted Aug 15, 2011, 3:29 AM
Sam HobbsPosted Aug 14, 2011, 8:00 PM