Murray Brown
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=Mur ray;pwd=.. ...;databa se=.....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.Va lue))
{
oAdminID = reader("AdminID").ToString ();
}
else
{
oAdminID = "";
}
if (!reader("Password").Equal s(DBNull.V alue))
{
oPassword = reader("Password").ToStrin g();
}
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;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
{
string oAdminID = null;
string oPassword = null;
string SQL = null;
SqlConnection myConnection = new SqlConnection("server=....
//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
{
oAdminID = reader("AdminID").ToString
}
else
{
oAdminID = "";
}
if (!reader("Password").Equal
{
oPassword = reader("Password").ToStrin
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER