Tuesday 21 August 2012

c# tutorial

CODE TO RETRIEVE PICTURES FROM DATABASE USING LINQ TO SQL

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace pictureProjectIlinqToSql
{
    public partial class Retrive_Picture : Form
    {
        public Retrive_Picture()
        {
            InitializeComponent();
        }

        private void btnretrive_Click(object sender, EventArgs e)
        {
            retrivePicture();
        }
        public void retrivePicture()
        {
            StudeterDataContext stud = new StudeterDataContext();
            StudentTB stutb = new StudentTB();
             byte[]pix =null;
            stutb = (from s in stud.StudentTBs where s.Matricno == txtboxmatricno.Text select s).Single<StudentTB>();
            pix = stutb.photo.ToArray();

            ImageConverter imageconv = new ImageConverter();
           pictureBoxretrivepicture.Image=(Image)imageconv.ConvertFrom(pix);
           pictureBoxretrivepicture.SizeMode = PictureBoxSizeMode.StretchImage;

        }
    }
}

No comments:

Post a Comment