[英]How Do I Find A Specific Image From My Database
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
)。
我的問題是,如何檢查該圖像是否已經存儲在數據庫中,如果是,請轉到應用程序的下一種形式。
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();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.