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 HobbsRank #107 · 20.5K reputationPosted Aug 14, 2011, 4:00 PM EDT
theLizardRank #1,079 · 1.8K reputationPosted Aug 14, 2011, 11:29 PM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2011, 3:00 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2011, 8:07 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Aug 15, 2011, 9:10 AM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2011, 10:09 AM EDT
David Chen60 reputationPosted Aug 15, 2011, 10:21 AM EDT
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
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2011, 10:38 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Aug 15, 2011, 11:11 AM EDT
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?
VulpesRank #55 · 29.2K reputationPosted Aug 15, 2011, 11:46 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Aug 15, 2011, 1:53 PM EDT
theLizardRank #1,079 · 1.8K reputationPosted Aug 15, 2011, 5:22 PM EDT
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..
David Chen60 reputationPosted Aug 15, 2011, 9:01 PM EDT
theLizardRank #1,079 · 1.8K reputationPosted Aug 15, 2011, 9:09 PM EDT
David Chen60 reputationPosted Aug 15, 2011, 9:13 PM EDT
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
Sam HobbsRank #107 · 20.5K reputationPosted Aug 15, 2011, 9:22 PM EDT
If we are going to continue to discuss it, then can you please try doing what I requested?
theLizardRank #1,079 · 1.8K reputationPosted Aug 15, 2011, 9:46 PM EDT
Severus Snapes4 reputationPosted Feb 10, 2014, 10:51 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 10, 2014, 11:20 AM EST
Tell you what, Severus. Try taking your own advice. Try providing some actual useful help. Can you do that?