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"); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)