private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(@"Data Source=SAZ-PC\SQLEXPRESS;Initial Catalog=Voted;Integrated Security=True");
SqlCommand cmd1 = new SqlCommand("select FINGERPRINT from Regdmem ", cn);
cn.Open();
Byte[] barrImg = (Byte[])cmd1.ExecuteScalar();
foreach (byte fp in barrImg)
{
Byte[] bytes = File.ReadAllBytes("D:\\Image.bmp");
bool cmp = barrImg.SequenceEqual(bytes);
if (cmp == true)
{
Form3 f3 = new Form3();
f3.Show();
this.Hide();
}
else
{
Application.Exit();
}
}
cn.Close();
}
在我的数据库中,我有一个名为FINGERPRINT
的列的表。在该列中,存储了多个图像。
我的硬盘上也有一张图片(D:\\Image.bmp
)。
我的问题是,如何检查此图像是否已存储在我的数据库中,如果是,请转到我的应用程序的下一个表单。
答案 0 :(得分:0)
ExecuteScalar
返回第一行第一列的值。您必须使用ExecuteReader
来获取所有图片。
Byte[] bytes = File.ReadAllBytes("D:\\Image.bmp");
SqlDataReader reader = cmd1.ExecuteReader();
while (reader.Read())
{
Byte[] barrImg = (Byte[])reader[0];
bool cmp = barrImg.SequenceEqual(bytes);
if (cmp == true)
{
Form3 f3 = new Form3();
f3.Show();
this.Hide();
}
else
{
Application.Exit();
}
}