-1

I am unable to find the problem here but this does not work! Any help will be appreciated.

It is a bool thing BTW.Every time i debug, it logs an error as follows

Invalid attempt to read when no data is present

ICCqueueLabelDropDownList.Items.Clear();
string queryString = "(SELECT  [name] FROM [asterisk].[dbo].[sip_friends] where name = '" + phoneNumberDropDownList.SelectedItem + "');";
        SqlConnection conn = new SqlConnection(connectionString);

        SqlCommand selectCmd = new SqlCommand(queryString, conn);
        SqlDataReader myReader = null;
        bool value = false;
        try
        {
            conn.Open();                                
            myReader = selectCmd.ExecuteReader();          

            //myReader.Read();

            if (myReader["name"].ToString() != "" )  /*   ( myReader["name"].ToString() != ""  */
            {
                myReader.Read();


                value = true;
            }





        }
        catch (Exception ex)
        {
            //ErrorLabel.Text = ex.Message;
            hiba.Visible = true;
            hiba.Text = ex.Message + "\n Check Insert Call User Device ÁLERT!";

        }
        myReader.Close();
        conn.Close();
        return (value);
    }
Nayantara Jeyaraj
  • 2,624
  • 7
  • 34
  • 63
Andrew
  • 1
  • 1
  • 4
    Possible duplicate of [Invalid attempt to read when no data is present](https://stackoverflow.com/questions/1147615/invalid-attempt-to-read-when-no-data-is-present) – mjwills Mar 27 '18 at 11:12

1 Answers1

0

@andrew, kindly go through below code and let me know is it working for you or not?

        string connectionString = "[YOUR_CONNECTION_STRING]";
        ICCqueueLabelDropDownList.Items.Clear();
        string queryString = "(SELECT  [name] FROM [asterisk].[dbo].[sip_friends] where name = '" + phoneNumberDropDownList.SelectedItem + "');";
        SqlConnection conn = new SqlConnection(connectionString);
        SqlCommand selectCmd = new SqlCommand(queryString, conn);
        SqlDataReader myReader = null;
        bool value = false;
        try
        {
            conn.Open();
            myReader = selectCmd.ExecuteReader();
            if (myReader.Read())
            {
                if (myReader["name"].ToString() != "")  
                {
                    value = true;
                }
            }
        }
        catch (Exception ex)
        {
        }
        myReader.Close();
        conn.Close();
        return (value);
    }
Priyal Pithadiya
  • 889
  • 1
  • 5
  • 12
  • HI! Thanks for your help, but it isn't working. Whenn i do this the web app does not pop up error, but the program doesn't go forward – Andrew Mar 27 '18 at 12:16
  • Can you please send a snap of error which you face i tried with given solution and it seems working for me as per your mention scenario. So if possible give me a code or snap of error. Thanks. – Priyal Pithadiya Mar 28 '18 at 04:27