Created
August 23, 2024 13:14
-
-
Save einnar82/39aca4492cb61befa7e8bd8b6a12d97e to your computer and use it in GitHub Desktop.
image.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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