1

I have a check box in my c# winform app. When I checked and save, it goes to MySQL table as a tinyint value (1). But When I try to retrieve that record, I was in a trouble.

 sql = "SELECT replacserial,recieveddate,replacedate,senttosupdate,sentcourier,tracknum, " +
                    "suppjobno,sentcomments,isrecievfromsupp,recievfromsuppdate,isreplaced,iscreditnote, " +
                    "replacedby,replacedcomment,issenttosup FROM warrantymanage WHERE id='" + strId +"' AND lcode='"+ Globe.locaCode +"'";
            config.singleResult(sql);
            if (config.dt.Rows.Count > 0)
            {

               
                bool isRecievedfromSup = false;
               

                //  isRecievedfromSup = Boolean.TryParse(config.dt.Rows[0].Field<int>("isrecievfromsupp").ToString());
                
                //isRecievedfromSup = config.dt.Rows[0].Field<bool>("isrecievfromsupp") as bool? ?? false;
                
                isRecievedfromSup = config.dt.Rows[0][8] as bool? ?? false;

It doesn't get the database value to the variable. Can anyone help me?

Mang
  • 23
  • 4
  • 2
    please use ***parameterised queries*** - building SQL queries by concatenation etc. is a recipe for disaster. not only is it a source for many hard to debug syntax errors, it's also a wide, open gate for ***[SQL Injection attacks](https://bobby-tables.com/)***. – Franz Gleichmann Dec 13 '21 at 12:32
  • Does this answer your question? [How do I retrieve a data type of tinyint from MySQL in C#?](https://stackoverflow.com/questions/10922928/how-do-i-retrieve-a-data-type-of-tinyint-from-mysql-in-c) – the.Doc Dec 13 '21 at 12:34
  • shouldn't a `tinyint` be treated as a `byte` in C#? is it only ever 0 or 1? – Marc Gravell Dec 13 '21 at 12:42
  • Does this answer your question? [How can I cast an int to a bit in MySQL 5.1?](https://stackoverflow.com/questions/6918897/how-can-i-cast-an-int-to-a-bit-in-mysql-5-1) – Charlieface Dec 13 '21 at 13:01
  • @MarcGravell `TINYINT` will be returned as `sbyte`, but `TINYINT(1)` (deprecated syntax that specifies the formatting width of the column in characters) will be returned as `bool`, as long as `Treat Tiny As Boolean = False` isn't added to the connection string (the default is `True`). – Bradley Grainger Dec 13 '21 at 14:54

0 Answers0