
while (reader.Read())
{
if (TextBox1.Text.CompareTo(reader["usernam"].ToString()) == 0&&TextBox2.Text.CompareTo(reader["passwd"].ToString()) == 0) // A little messy but does the job to compare your infos assuming your using a textbox for username and password
{
Label3.Text = "Redirecting";
Response.Cookies["dbname"]["Name"] = reader["usernam"].ToString();
Response.Cookies["dbname"].Expires = DateTime.Now.AddSeconds(10);
Response.Redirect("index2.aspx");
}
else
{ Label3.Text = "NO"; }
}
When i try to compare both username (usernam) and password (passwd) I get this error. If i only compare the username with the db entries it works like a charm.

It will only give the error when actual data is used. E.I. If i enter [admin], [admin] in the log in web page it will give me the error, if i enter [asd], [asd] then the label would change to NO.
The idea behind the code is a log in page. I hope my explanation is good enough.