Search code examples
c#sqlsql-serverweb-serviceswebmethod

Webservice returning byte array


I have a webservice that gets a list of byte[] from the db. I want to be able to return all the values. How do I return a byte[].

 [WebMethod]
        public List<fgrTemplate> StudentVerifications()
         {
            List<fgrTemplate> listOfFgrTemp = new List<fgrTemplate>();
            cn.Open();
            SqlCommand com = new SqlCommand("SELECT Template FROM tblFingerprint", cn);
            SqlDataReader sr = com.ExecuteReader();
            while (sr.Read())
            {
                fgrTemplate fingerprint = new fgrTemplate()
                {
                    ID = sr.GetInt32(0),
                    StudentID = sr.GetInt32(1),
                    Description = sr.GetString(2)
                    Template = sr.GetByte??
                };
 listOfFgrTemp.Add(fingerprint);
  }

            cn.Close();
            return listOfFgrTemp;

        }

Solution

  • Like this:

    Template = (byte[])sr[3];
    

    OR

    Template = (byte[])sr["Template"];