title: How to store fingerprint template to sql server
body: <p>I am having trouble in storing fpt templates in SQL Server.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Text;
  using System.Windows.Forms;
  using System.IO;
  
  //imports
  using DHELTASSys.AuditTrail;
  using DHELTASSys.Modules;
  
  namespace Enrollment
  {
      delegate void Function();   // a simple delegate for marshalling calls from event handlers to the GUI thread
  
      public partial class CreateAccount : Form
      {
          HRModuleBL obj = new HRModuleBL();
          DHELTASSysAuditTrail audit = new DHELTASSysAuditTrail();
  
          public CreateAccount(int emp_id)
          {
              InitializeComponent();
              audit.Emp_id = emp_id;
          }
  
          protected void EmptyFields()
          {
  
          }
  
          private void CloseButton_Click(object sender, EventArgs e)
          {
              Close();
          }
  
  
          private void OnTemplate(DPFP.Template template)
          {
              this.Invoke(new Function(delegate()
              {
                  Template = template;
                  VerifyButton.Enabled = SaveButton.Enabled = (Template != null);
                  if (Template != null)
                      MessageBox.Show("The fingerprint template is ready for verification and saving", "Fingerprint Enrollment");
                  else
                      MessageBox.Show("The fingerprint template is not valid. Repeat fingerprint enrollment.", "Fingerprint Enrollment");
              }));
          }
  
          private DPFP.Template Template;
  
  
  
  
  
  
  
  
          private void EnrollButton_Click(object sender, EventArgs e)
          {
              EnrollmentForm Enroller = new EnrollmentForm();
              Enroller.OnTemplate += this.OnTemplate;
              Enroller.ShowDialog();
          }
  
          private void SaveButton_Click(object sender, EventArgs e)
          {
              obj.Last_name = txtLastname.Text;
              obj.First_name = txtFirstName.Text;
              obj.Middle_name = txtMiddleName.Text;
              obj.Position_name = cmbPosition.Text;
              obj.Company_name = cmbCompany.Text;
              obj.Password = txtTempPassword.Text;
              obj.Department_name = cmbDepartment.Text;
  
              if (obj.Last_name == string.Empty) //Validation for empty texts
              {
                  MessageBox.Show("Last name can't be empty!");
              } else if (obj.First_name == string.Empty) 
              {
                  MessageBox.Show("First name can't be empty!");
              }
              else if (obj.Middle_name == string.Empty)
              {
                  MessageBox.Show("Middle name can't be empty!");
              }
              else if (obj.Position_name == string.Empty)
              {
                  MessageBox.Show("Position name can't be empty!");
              }
              else if (obj.Department_name == string.Empty)
              {
                  MessageBox.Show("Deparment can't be empty!");
              }
              else if (obj.Company_name == string.Empty)
              {
                  MessageBox.Show("Company name can't be empty!");
              }
              else if (obj.Password == string.Empty)
              {
                  MessageBox.Show("Password can't be empty!");
              }
              else if (txtConfirmTempPassword.Text == string.Empty)
              {
                  MessageBox.Show("Please verify your input password!");
              }
              else
              {
  
                  if (txtTempPassword.Text != txtConfirmTempPassword.Text)
                  {
  
                      MessageBox.Show("Password does not match", "Password Mismatch",
                          MessageBoxButtons.OK);
                  }
                  else
                  {
                      MemoryStream fingerprintData = new MemoryStream();
                      Template.Serialize(fingerprintData);
                      fingerprintData.Position = 0;
                      BinaryReader br = new BinaryReader(fingerprintData);
                      byte[] bytes = br.ReadBytes((Int32)fingerprintData.Length);
  
                      obj.Biometric_code = bytes;
                      obj.AddAccountSetTempPassword();
                      audit.AddAuditTrail("Created account for " + obj.First_name + " " + obj.Last_name + ".");
  
                      MessageBox.Show("Account Created for " + txtLastname.Text + "," + txtFirstName.Text);
  
                      txtConfirmTempPassword.Text = "";
                      txtFirstName.Text = "";
                      txtLastname.Text = "";
                      txtMiddleName.Text = "";
                      txtTempPassword.Text = "";
                      cmbCompany.Text = "";
                      cmbDepartment.Text = "";
                      cmbPosition.Text = "";
  
                  }
              }
          }
  
          private void VerifyButton_Click(object sender, EventArgs e)
          {
              VerificationForm Verifier = new VerificationForm();
              Verifier.Verify(Template);
          }
      }
  }
  </code></pre>
  
  <p>Wherein I have initiated the object <code>obj</code> for the class used to insert data to SQL Server.
  Using the <code>AddAccountSetTempPassword()</code> method, I store the data into the database.</p>
  
  <p>Problem is, when I look into the database, the image field for all fingerprint data is written as this <code>0x53797374656D2E427974655B5D</code>.</p>
  
  <p>UPDATE #1
  Here is the class that I used to insert data into the database.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  //Imports
  using System.Data;
  using DHELTASSys.DataAccess;
  using DHELTASSys.AuditTrail;
  
  namespace DHELTASSys.Modules
  {
      class HRModuleBL
      {
          DHELTASSysAuditTrail audit = new DHELTASSysAuditTrail();
  
          private int emp_id;
          public int Emp_id
          {
              get { return emp_id; }
              set { emp_id = value; }
          }
  
          private string password;
          public string Password
          {
              get { return password; }
              set { password = value; }
          }
  
          private string last_name;
          public string Last_name
          {
              get { return last_name; }
              set { last_name = value; }
          }
  
          private string first_name;
          public string First_name
          {
              get { return first_name; }
              set { first_name = value; }
          }
  
          private string middle_name;
          public string Middle_name
          {
              get { return middle_name; }
              set { middle_name = value; }
          }
  
          private string position_name;
          public string Position_name
          {
              get { return position_name; }
              set { position_name = value; }
          }
  
          private string company_name;
          public string Company_name
          {
              get { return company_name; }
              set { company_name = value; }
          }
  
          private string email;
          public string Email
          {
              get { return email; }
              set { email = value; }
          }
  
          private string gender;
          public string Gender
          {
              get { return gender; }
              set { gender = value; }
          }
  
          private string address;
          public string Address
          {
              get { return address; }
              set { address = value; }
          }
  
          private string primary_Number;
          public string Primary_Number
          {
              get { return primary_Number; }
              set { primary_Number = value; }
          }
  
          private string alternative_Number;
          public string Alternative_Number
          {
              get { return alternative_Number; }
              set { alternative_Number = value; }
          }
  
          private string city;
          public string City
          {
              get { return city; }
              set { city = value; }
          }
  
          private DateTime birthdate;
          public DateTime Birthdate
          {
              get { return birthdate; }
              set { birthdate = value; }
          }
  
          private int sss_Number;
          public int Sss_Number
          {
              get { return sss_Number; }
              set { sss_Number = value; }
          }
  
          private int philHealth_number;
          public int Philhealth_number
          {
              get { return philHealth_number; }
              set { philHealth_number = value; }
          }
  
          private byte[] biometric_code;
          public byte[] Biometric_code
          {
              get { return biometric_code; }
              set { biometric_code = value; }
          }
  
          private string employee_status;
          public string Employee_status
          {
              get { return employee_status; }
              set { employee_status = value; }
          }
  
          private int company_id;
          public int Company_id
          {
              get { return company_id; }
              set { company_id = value; }
          }
  
          private string department_name;
          public string Department_name
          {
              get { return department_name; }
              set { department_name = value; }
          }
  
          //Methods
  
          //Create account and set temporary password for employee
  
          public void AddAccountSetTempPassword()
          {
              if (Position_name == "Supervisor") //If employee is supervisor
              {
                  string cmd = "EXECUTE AddAccountSetTempPassword '" + Password + "',"
                  + "'" + Last_name + "',"
                  + "'" + First_name + "',"
                  + "'" + Middle_name + "',"
                  + "'" + Position_name + "',"
                  + "'" + Company_name + "',"
                  + "'" + Department_name + "',"
                  + "'" + Biometric_code + "'";
                  DHELTASSysDataAccess.Modify(cmd);
  
                  string cmdTwo = "Execute AddSupervisor";
                  DHELTASSysDataAccess.Modify(cmdTwo);
              }
              else //If employee isn't a supervisor
              {
                  string cmd = "EXECUTE AddAccountSetTempPassword '" + Password + "',"
                  + "'" + Last_name + "',"
                  + "'" + First_name + "',"
                  + "'" + Middle_name + "',"
                  + "'" + Position_name + "',"
                  + "'" + Company_name + "',"
                  + "'" + Department_name + "',"
                  + "'" + Biometric_code + "'";
                  DHELTASSysDataAccess.Modify(cmd);
  
              }
  
  
  
          }
  
  
          //Employee will enter permanent password for account
          public void AddPermanentPasswordForAccount()
          {
              string cmd = "EXECUTE AddPermanentPasswordForAccount"
                  + "'" + Password + "',"
                  + "'" + Emp_id + "',";
              DHELTASSysDataAccess.Modify(cmd);
              //DHELTASSysAuditTrail.AddAuditTrail( "Changed password.");
          }
  
          //Employee adds his/her account details
          public void AddAccountDetails()
          {
              string cmd = "EXECUTE AddAccountDetails"
                  + "'" + Email + "',"
                  + "'" + Gender + "',"
                  + "'" + Address + "',"
                  + "'" + Primary_Number + "',"
                  + "'" + Alternative_Number + "',"
                  + "'" + City + "',"
                  + "'" + Birthdate + "',"
                  + "'" + Sss_Number + "',"
                  + "'" + Philhealth_number + "',"
                  + "'" + Emp_id + "'";
              DHELTASSysDataAccess.Modify(cmd);
              //DHELTASSysAuditTrail.AddAuditTrail("Account details updated.");
          }
  
          //Displays all employees' information
          public DataTable ViewEmployeeInformation()
          {
              string cmd = "EXECUTE ViewEmployeeInformation"
                  + "'" + Company_id + "'";
              DataTable dtEmployees = DHELTASSysDataAccess.Select(cmd);
              return dtEmployees;
          }
  
          //Verifies account login in the forms application
          public DataTable AccountEnrollmentLogin()
          {
              string cmd = "EXECUTE AccountEnrollmentLogin"
                  + "'" + Emp_id + "',"
                  + "'" + Password + "'";
              DataTable dt = DHELTASSysDataAccess.Select(cmd);
              return dt;
          }
  
          //Check if HR Manager
          public DataTable CheckIfHRManager()
          {
              string cmd = "EXECUTE CheckIfHRManager"
                  + "'" + Emp_id + "'";
              DataTable dt = DHELTASSysDataAccess.Select(cmd);
              return dt;
          }
      }
  }
  </code></pre>
  
  <p>And the table looks like this:</p>
  
  <pre><code>table : employee
  emp_id-&gt;int-&gt;PK
  password-&gt;nvarchar(MAX)
  last_name-&gt;varchar(50)
  first_name-&gt;varchar(50)
  middle_name-&gt;varchar(50)
  position_id-&gt;int-&gt;FK
  department_id-&gt;int-&gt;FK
  company_id-&gt;int-&gt;FK
  email_address-&gt;varchar(50)
  gender-&gt;varchar(10)
  address-&gt;varchar(100)
  primary_contact_number-&gt;varchar(20)
  alternative_contact_number-&gt;varchar(20)
  city-&gt;varchar(50)
  birthdate-&gt;date
  sssNumber-&gt;int
  philhealth_number-&gt;int
  employee_status-&gt;bit
  biometrics_image-&gt;image
  </code></pre>
  
  <p>I wish to convert the template into bytes to save it into the database.
  Thanks in advance.</p>