adspace
hi all.... i need code snippets for store and retrive tiff
fromat images in sqlserver....... kindy provide it.......
Answer Posted / Naman Agarwal
Here is a basic example of how you can store and retrieve TIFF images using C# and SQL Server. Please note that this is a simplified example and might need to be adjusted based on your specific needs.nnStoring image:n```csharpnusing System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;n
Byte[] imgBytes = null;
Image img = Image.FromFile(@"path_to_your_image");
img.Save(new MemoryStream(imgBytes), ImageFormat.Tiff);n
SqlConnection con = new SqlConnection("Your Connection String");
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO Images (ImageData) VALUES (@Image)", con);
cmd.Parameters.AddWithValue("@Image", imgBytes);
cmd.ExecuteNonQuery();
con.Close();n```nnRetrieving image:n```csharpnByte[] imgBytes = null;
SqlConnection con = new SqlConnection("Your Connection String");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT ImageData FROM Images WHERE Id = @Id", con);
cmd.Parameters.AddWithValue("@Id", Your_Image_ID);
imgBytes = (Byte[])cmd.ExecuteScalar();
MemoryStream ms = new MemoryStream(imgBytes);
Image img = Image.FromStream(ms);n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers