Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai,
how can i store and retrieve a binary file(fingerprint template file) in sql server in c#.net
thanks in advance!
Posted

 
Share this answer
 
 
Share this answer
 
Set up a varbinary or image column in your database.
Then just insert it:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    byte[] bytes = GetTheByteData();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myBinaryDataColumnName) VALUES (@BINDATA)", con))
        {
        com.Parameters.AddWithValue("@BINDATA", bytes);
        com.ExecuteNonQuery();
        }
    }


To extract it:
C#
byte[] bytes;
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT myBinaryDataColumnName FROM myTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            if (reader.Read())
                {
                bytes = (byte[]) reader["myBinaryDataColumnName"];
                }
            }
        }
    }
Obviously, you will want to filter the returned values with a WHERE clause on the SELECT statement to just retrieve the one you are interested in.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900