Click here to Skip to main content
15,905,971 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have employ table which contains empid,empname,empimage..
nowi want to store data from front and retrive data from backend using datareader including image also..

empid:1
empname:xxx
empimage:hisimage in image url
Posted

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;
using System.Data.SqlClient;
using System.IO;
using System.Drawing.Imaging;
namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {

        SqlConnection con = new SqlConnection("Data Source=VARNAR12;Initial Catalog=master;Integrated Security=True");
        SqlCommand com = new SqlCommand();
        static MemoryStream ms;
        SqlDataReader dr;
        public Form1()
        {
            InitializeComponent();
            SqlCommand com = new SqlCommand("SELECT picid, " + "picdata FROM pic ORDER BY picid", con);
            dr = default(SqlDataReader);
            con.Open();
            dr = com.ExecuteReader();
        }
 private void Form1_Load(object sender, EventArgs e)
        {
           
        }
       
        private void button2_Click_1(object sender, EventArgs e)
        {
           <pre lang="cs">if (dr.Read())
            {
                label1.Text = dr[0].ToString();

                byte[] pic1 = new byte[dr.GetBytes(1, 0, null, 0, int.MaxValue)];
                dr.GetBytes(1, 0, pic1, 0, pic1.Length);
                MemoryStream stmdata = new MemoryStream(pic1);
                pictureBox1.Image = Image.FromStream(stmdata);
            }

            dr.Close();

        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900