29_نمایش تصاویر ذخیره شده در جدول
توضیحات : ابتدا یک ListBox و یک PictureBox به فرم اضافه نمائید
using System.Data.SqlClient;
using System.IO;
protected SqlDataAdapter da;
protected DataSet dsPictures;
protected SqlCommandBuilder cbd;
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedIndex < 0)
{
MessageBox.Show("تصویری برای نمایش وجود ندارد");
}
else
{
byte[] buffer1 = (byte[])dsPictures.Tables[0].Rows
[listBox1.SelectedIndex]["Picture"];
MemoryStream stream1 = new MemoryStream(buffer1);
PictureBox box1 = pictureBox1;
box1.Image = Image.FromStream(stream1);
box1.SizeMode = PictureBoxSizeMode.CenterImage;
box1.BorderStyle = BorderStyle.Fixed3D;
box1 = null;
stream1.Close();
}
}
private void Form7_Load(object sender, EventArgs e)
{
pictureBox1.BorderStyle = BorderStyle.FixedSingle;
listBox1.BorderStyle = BorderStyle.FixedSingle;
try
{
string strConnection = @"Data Source = ARASH-PC\ARASH; Initial Catalog = SampleDB; User Id = sa; Password = 1;";
SqlConnection connection1 = new SqlConnection(strConnection);
SqlCommand command1 = new SqlCommand("SELECT dbo.Pictures.* FROM dbo.Pictures", connection1);
da = new SqlDataAdapter(command1);
cbd = new SqlCommandBuilder(da);
dsPictures = new DataSet();
da.Fill(dsPictures);
ListBox box1 = listBox1;
box1.DataSource = dsPictures.Tables[0];
box1.DisplayMember = "Name";
box1 = null;
}
catch (Exception exception1)
{
MessageBox.Show("مشکلی پیش آمده است");
}
}
لطفا پست نزنید 
در صورتی که در خصوص هر آنچه که در این تاپیک مطرح شده سوالی دارید می توانید آن را در تاپیک سوالهای مربوط به تاپیک آموزش برنامه نویسی پایگاه داده به همراه مثالهای کاربردی مطرح کنید
مشاهده لیست
مشاهده نکته های سی شارپ ...