Skip to content

Instantly share code, notes, and snippets.

@einnar82
Created August 23, 2024 13:14
Show Gist options
  • Save einnar82/39aca4492cb61befa7e8bd8b6a12d97e to your computer and use it in GitHub Desktop.
Save einnar82/39aca4492cb61befa7e8bd8b6a12d97e to your computer and use it in GitHub Desktop.
image.cs
using System.Data.SqlClient;
using System.Drawing;
// ...
SqlConnection connection = new SqlConnection("your_connection_string");
SqlCommand command = new SqlCommand("SELECT TOP 1 MunMap FROM tblmunicipality", connection);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
byte[] imageData = (byte[])reader["MunMap"];
using (MemoryStream ms = new MemoryStream(imageData))
{
Image image = Image.FromStream(ms);
pictureBox1.Image = image;
}
}
}
catch (Exception ex)
{
// Handle exceptions appropriately
Console.WriteLine("Error: " + ex.Message);
}
finally
{
connection.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment