私は2つの文字列を比較しています。1つはデータベースからのもので、もう1つは比較自体に入力されたものです。しかし、同一の文字列を比較しようとすると、誤った結果が得られます。
現在、私のコードは次のとおりです。
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");
}