0
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();
}

In my database I have a table with a column named FINGERPRINT. In that column, multiple images are stored.

I also have an image on my harddrive (D:\\Image.bmp).

My question is, how do I check whether this image is already stored in my database and if so, go to the next form of my application.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Legend
  • 79
  • 1
  • 9

1 Answers1

0

ExecuteScalar returns the value from first column of first row. You must use the ExecuteReader to get all images.

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();
    }
}
Hamlet Hakobyan
  • 32,965
  • 6
  • 52
  • 68
  • Thanx for your response it is working but it also exiting the application when i comment out the application.exit() its working fine – Legend Apr 13 '14 at 12:57