• Hi everyone,

    I have a problem with the codes below.

    I have a table whose name is "debTap". At the below you can see, i use a variable "tempFirmID" which is an int.

    i replace the "tempFirmID" with a number ,such as 11, the code works good. However, if i use the "tempFirmID" there is no error and no result. Because, reader.Read() returns false.

    what is the problem ?

    thanks for your interest.

    string query = "SELECT * FROM depTab WHERE FirmID = '" + tempFirmID + "';" ;
    MySqlCommand sqlcmd = new MySqlCommand(query, dbcon.connection);
    MySqlDataReader reader = sqlcmd.ExecuteReader();
    while (reader.Read())
              tempValue = reader.GetString("depName");
              if (tempDepName == tempValue )
                    durum = false;
              else {durum = true;}

    Saturday, April 8, 2017 7:20 AM

All replies

  • Hi

    in your query you are using single quotes is the Firm Id field of type string?

    if not then use the query as 

    string query = "SELECT * FROM depTab WHERE FirmID = " + tempFirmID.ToString() + " ;" ;


    Surender Singh Bhadauria

    My Blog


    Saturday, April 8, 2017 9:13 AM
  • I try your advice, too. However the result is same.

    Actually, I get the value of tempFirmID from a other mysql table.

    I check the value of tempFirmID and the number 11 equivalences. They are not equal.

    if (tempFirmaID == 11) MessageBox.Show("equal");
    else MessageBox.Show("no equal"); 

    tempFirmID = reader.GetInt32("firID");
    what is the difference between tempFirmID and the number 11 ?

    Saturday, April 8, 2017 9:41 AM
  • Try displaying the value of the variable in a message box. Because if it would have been a text field there was a minor possiblity of it being a unicode counter part but in your case its a numeric value.

    Other than that what is the datatype of the field in DB


    Surender Singh Bhadauria

    My Blog


    Saturday, April 8, 2017 9:59 AM
  • I check thet datatype of tempFirmID. It is int32.

    mysql data tyepes:
    firmID INT(11)

    c# variables:

    int tempFirmID;

    Saturday, April 8, 2017 10:44 AM
  • what was displayed when you tried to display the value of tempfirmid in the messagebox?


    Surender Singh Bhadauria

    My Blog


    Saturday, April 8, 2017 10:48 AM
  • dear Surender Singh Bhadauria,

    messagebox messages are below;

    for string  query : SELECT * FROM departman WHERE departmanFirmaID = 11

    for value of tempFirmID : 11

    for datatype of tempFirmID : System.int32

    thanks for your interest

    Saturday, April 8, 2017 11:46 AM