Click here to Skip to main content
15,886,732 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Am developing a project to capture an finger print image from the biometric device and store it in database. My question is "Is it good to store the image directly into the database or store it in file and store the path of the file into the database." Please send the code to both cases.
Posted

It is useful if you store the images in a folder and store only path of that images in sql server database.
 
Share this answer
 
hi you should define a field varbinary(MAX) in database
then use this code
FileStream file = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
            BinaryReader str1 = new BinaryReader(file);
            byte[] bit = str1.ReadBytes(Convert.ToInt32( file.Length));
            SqlConnection connection = new SqlConnection("server=(local);database=test;integrated security=true");
            connection.Open();
            SqlCommand command = new SqlCommand();
            command.Connection = connection;
            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@Photo",bit);
            command.CommandText = "INSERT INTO image1(pic) VALUES (@Photo)";
            command.ExecuteNonQuery();
            connection.Close();
 
Share this answer
 
Comments
Anuradha Salim 9-Nov-12 12:30pm    
Can you explain the code for retrieving image from the database sqlserver 2008?
Ideally you should not store the entire image into database. Store only path of that image.
 
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