Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net C# "reader is a variable but is used like a method"

Hi. I am trying to use the following code to read through a SQL table to check if a userID and password exist. I converted the code from a VB.net project and am getting an error on the word reader - "reader is a variable but is used like a method"



        protected void Button1_Click(object sender, EventArgs e)
        {
            {
                string oAdminID = null;
                string oPassword = null;
                string SQL = null;

                SqlConnection myConnection = new SqlConnection("server=......;uid=Murray;pwd=.....;database=.....y");

                //Dim command As SqlCommand = New SqlCommand("SELECT * From Reviewers;", myConnection)

                SQL = "SELECT * From Administrators";
                SqlCommand command = new SqlCommand(SQL, myConnection);

                try
                {
                    myConnection.Open();

                    SqlDataReader reader = command.ExecuteReader();


                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            if (!reader("AdminID").Equals(DBNull.Value))
                            {
                                oAdminID = reader("AdminID").ToString();
                            }
                            else
                            {
                                oAdminID = "";
                            }
                            if (!reader("Password").Equals(DBNull.Value))
                            {
                                oPassword = reader("Password").ToString();
                            }
                            else
                            {
                                oPassword = "";
                            }


                            if (oAdminID == this.AdminID.Text)
                            {

                                if (oPassword == Password.Text)
                                {
                                    this.Label_LoggedIn.Text = "Logged in:";
                                    this.Label_Reviewer.Text = oAdminID;


                                    this.Label_Error1.Text = "";
                                    this.Panel1.Visible = true;

                                }
                                else
                                {
                                    this.Label_Error1.Text = "The password that you entered does not match the Reviewer namee.";
                                }
                            }
                            else
                            {
                                this.Label_Error1.Text = "The username entered does not exist";
                            }

                        }
                    }
                    else
                    {
                        //Console.WriteLine("No rows found.")
                    }

                    reader.Close();

                    myConnection.Close();

                }
                catch (Exception ex)
                {
                    this.Label_Error1.Text = ex.Message;
                }
            }

        }
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

thanks for the help