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


Please Help Members By Posting Answers For Below Questions

Which namespaces are necessary to create a localized application?

1151


Why can't we use a static class instead of singleton?

963


What is an abstract class c#?

981


What is expression tree in c#?

1008


How do you inherit a class into other class in c#?

1001


How to assign Null value to Var?

1074