locked
Error - Cannot implicitly convert type int to boolean RRS feed

  • Question

  • User-797751191 posted

    Hi

       I am getting above error on below line - 

    if (count = 1)

    Int32 count = (Int32)cmd.ExecuteScalar();
    if (count = 1)
    {
    SqlCommand cmdupdate = new SqlCommand("Update tbl_test SET Url='" + AFile + "' where [Invoice No]='" + txtInvoiceNo.Text + "', con);
    con.Open();
    cmdupdate.CommandType = CommandType.Text;
    cmdupdate.ExecuteNonQuery();
    }

    Thanks

    Monday, June 24, 2019 2:03 PM

Answers

  • User753101303 posted

    Hi,

    = is the assignement and so you are doing if (1) whichs shows this error message. Checking egality is done using == :

    if (count==1) // compares count and 1 which gives a boolean...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 24, 2019 2:07 PM