【发布时间】:2015-09-08 12:45:25
【问题描述】:
我正在做一个人脸识别项目,我想将x.label 返回的值与保存到数据库中的ID 进行比较。
在将 ID 与 x.label 进行比较时,if 条件下总是出错
public int Predict(Image<Gray, Byte> testImage)
{
Emgu.CV.FaceRecognizer.PredictionResult x;
if (testImage != null)
{
x= fr.Predict(testImage);
pictureBox1.Image = testImage.ToBitmap();
//MessageBox.Show(x.Label.ToString()+" "+x.Distance.ToString());
OleDbCommand D1 = new OleDbCommand("Select [ID] FROM [connect]", DBConnection);
OleDbDataReader reader = D1.ExecuteReader();
while (reader.Read())
{
if (Convert.ToInt32(reader["ID"]) == x.Label)
{
OleDbCommand insert1 = new OleDbCommand("UPDATE OutputReport SET [Attendance]='yes' WHERE [StudentID]='109';", DBConnection);
insert1.ExecuteNonQuery();
MessageBox.Show(" its working");
}
}
RefreshDBConnection();
if (x.Distance < 69)
return x.Label;
else
MessageBox.Show("Error!!, The detected Face is neither recognised nor enrolled");
return -1;
}
else
{
return -1;
}
}
【问题讨论】:
-
...您总是遇到什么错误?
-
错误 1 当前上下文中不存在名称“ID”
-
@mariam 这个ID是来自数据库吗??
-
该代码几乎无法满足您的需求。由于
else部分没有块,因此只有MessageBox.Show是else块的一部分,因此您将始终返回-1。另外,你还没有声明D1,你只是想给它一个值。
标签: c# database ms-access if-statement face-recognition