各位大侠,我是个.NET新手,有个问题向大家请教。我想做个登陆程序,但是通过getstring()取出的字符串与Textbox里输入的字符串即使一样,在比较时也显示不同,小弟百思不得其解,请各位大侠指教,下面是部分代码:
protected void Button1_Click(object sender, EventArgs e)
{
string gh = TextBox1.Text;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=WLEI;Initial Catalog=MIS;User ID=sa;Password=3329 ";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select gh,pwd from employee where gh= ' "+gh+ " ' ";
cmd.Connection = conn;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
try
{
if (reader.Read())
{
if (reader.GetString(1) == TextBox2.Text)
{
Response.Write( "OK ");
}
else
{
Response.Write( "bad ");
}
}
else
{
Response.Write( "no such user ");
}
}
finally
{