我正在比较两个字符串,一个来自数据库,另一个是在比较本身中输入的。但是当我尝试比较相同的字符串时,它会给出错误的结果。
目前我的代码是:
SqlConnection conchk = new SqlConnection();
conchk.ConnectionString = "Data Source=localhost;Initial Catalog=eVoting;Integrated Security=True;Pooling=False";
conchk.Open();
SqlCommand cmdchk = new SqlCommand("select voted from voter where FirstName ='" + N + "'", conchk);
SqlDataReader readerchk = cmdchk.ExecuteReader();
readerchk.Read();
String vchk = readerchk[0].ToString();
String chk = "N";
MessageBox.Show(vchk);
int cas = chk.CompareTo(vchk);
MessageBox.Show("comp res :" + cas);
if (cas == 0)
{
MessageBox.Show("In if");
}
else
{
MessageBox.Show("In else");
}