Click here to Skip to main content
15,909,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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;

namespace assign
{
    public partial class Registerpage : Form
    {
        public Registerpage()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "")
            {

                string empid = textBox1.Text;
                string emppass = textBox2.Text;
                string empname = textBox3.Text;
                string empadd = richTextBox1.Text;
                string empimg = label5.Text;
                SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=emp;Integrated Security=True");
                MemoryStream ms = new MemoryStream();
                pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] pic_arr = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(pic_arr, 0, pic_arr.Length);

                SqlCommand cmd = new SqlCommand("insert into emp1(empid,emppass,empname,empadd,empimg) values(@empid,@emppass,@empname,@empadd,@empimg)",con);
                cmd.Parameters.AddWithValue("@empid",textBox1.Text);
                cmd.Parameters.AddWithValue("@emppass", textBox2.Text);
                cmd.Parameters.AddWithValue("@empname", textBox3.Text);
                cmd.Parameters.AddWithValue("@empadd", richTextBox1.Text);
                cmd.Parameters.AddWithValue("@empimg", pic_arr);


                con.Open();
                try
                {
                    int i = cmd.ExecuteNonQuery();
                    if (i < 0)
                    {
                        MessageBox.Show("Registration Completed...!");
                        textBox1.Text = "";
                        textBox2.Text = "";
                        textBox3.Text = "";
                        richTextBox1.Text = "";
                        label5.Text = "";

                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    con.Close();
                }
            }
            else
            {
                MessageBox.Show("Fill up the registration filleds");
            }





        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            label5.Text = openFileDialog1.FileName;
            //For diplaying image.
            string empimg = label5.Text;
            FileInfo fobj = new FileInfo(empimg);
            if (fobj.Exists)
            {
                pictureBox1.Image = Image.FromFile(empimg);
            }
            else
            {
                MessageBox.Show("Not Uploaded");
            }
        }
    }
}
[Edit]Code block added[/Edit]
Posted
Updated 9-Apr-13 21:29pm
v2
Comments
Richard MacCutchan 10-Apr-13 3:36am    
What and where?
vikram_bullet 10-Apr-13 12:45pm    
Can you specify what exactly is the error you are facing>
Member 9977408 11-Apr-13 13:25pm    
i am getting an error "cannot insert explicit value for identify column in table 'emp1' when IDENTITY_INSERT is set to OFF."

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