using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace YourNamespace
{
public partial class YourForm : Form
{
SqlConnection con = new SqlConnection("your_connection_string");
public YourForm()
{
InitializeComponent();
}
private void YourForm_Load(object sender, EventArgs e)
{
LoadGridData();
}
private void LoadGridData()
{
SqlDataAdapter da = new SqlDataAdapter("SELECT id, name, status, image
FROM your_table", con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
txtName.Text = row.Cells["name"].Value.ToString();
lblStatus.Text = row.Cells["status"].Value.ToString();
if (row.Cells["image"].Value != DBNull.Value)
{
byte[] imageData = (byte[])row.Cells["image"].Value;
using (MemoryStream ms = new MemoryStream(imageData))
{
pictureBox1.Image = Image.FromStream(ms);
}
}
else
{
pictureBox1.Image = null;
}
}
}
}
}