Elamparithi K

Elamparithi K

  • NA
  • 18
  • 2.6k

I have error in delete option in image upload and retrieve

Jul 3 2012 8:00 AM

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

Microsoft.VisualBasic;

using

System.IO;

using

System.Drawing.Imaging;

namespace

{


WindowsFormsApplication3public partial class Form1 : Form

{


{

InitializeComponent();

}









{

con =

loaddata();

showdata();

}


{

cmd =

cmd.CommandType =

adapter.MissingSchemaAction =

ds =

}


{


{

textBox1.Text = ds.Tables[0].Rows[eno][0].ToString();

textBox2.Text = ds.Tables[0].Rows[eno][1].ToString();

comboBox1.Text = ds.Tables[0].Rows[eno][2].ToString();


pictureBox1.Image =


{

photo_aray = (


pictureBox1.Image =

}

}


public Form1()SqlConnection con;SqlCommand cmd;SqlDataAdapter adapter;DataSet ds; int eno = 0;MemoryStream ms;byte[] photo_aray;private void Form1_Load(object sender, EventArgs e)new SqlConnection("Data Source=user-pc;Initial Catalog=oom;User ID=sa;Password=sa123");void loaddata()new SqlCommand("get_emp", con);CommandType.StoredProcedure; adapter = new SqlDataAdapter(cmd);MissingSchemaAction.AddWithKey;new DataSet(); adapter.Fill(ds, "emp");void showdata()if (ds.Tables[0].Rows.Count > 0)null;if (ds.Tables[0].Rows[eno][3] != System.DBNull.Value)byte[])ds.Tables[0].Rows[eno][3];MemoryStream ms = new MemoryStream(photo_aray);Image.FromStream(ms);else


}


{

openFileDialog1.Filter =



{

pictureBox1.Image =

}

}


{

textBox1.Text = textBox2.Text =

comboBox1.Text =

pictureBox1.Image =

}


{

cmd =

cmd.CommandType =

cmd.Parameters.AddWithValue(

cmd.Parameters.AddWithValue(

cmd.Parameters.AddWithValue(


conv_photo();

con.Open();


con.Close();


{


loaddata();

}


MessageBox.Show("No Records");private void button1_Click(object sender, EventArgs e)"jpeg|*.jpg|bmp|*.bmp|all files|*.*";DialogResult res = openFileDialog1.ShowDialog();if (res == DialogResult.OK)Image.FromFile(openFileDialog1.FileName);private void button6_Click(object sender, EventArgs e)"";"SELECT";null;private void button7_Click(object sender, EventArgs e)new SqlCommand("insert_emp", con);CommandType.StoredProcedure;"@eno", textBox1.Text);"@ename", textBox2.Text);"@gender", comboBox1.Text);int n = cmd.ExecuteNonQuery();if (n > 0)MessageBox.Show("record inserted");else


}


{


MessageBox.Show("insertion failed");void conv_photo()//converting photo to binary data


{

ms =

pictureBox1.Image.Save(ms,


ms.Position = 0;

ms.Read(photo_aray, 0, photo_aray.Length);

cmd.Parameters.AddWithValue(

}

}


{


if (pictureBox1.Image != null)new MemoryStream();ImageFormat.Jpeg);byte[] photo_aray = new byte[ms.Length];"@photo", photo_aray);private void button9_Click(object sender, EventArgs e)try

{



drow = ds.Tables[0].Rows.Find(n);


{

eno = ds.Tables[0].Rows.IndexOf(drow);

textBox1.Text = drow[0].ToString();

textBox2.Text = drow[1].ToString();

comboBox1.Text = drow[2].ToString();


pictureBox1.Image =


{

photo_aray = (


pictureBox1.Image =

}

}


int n = Convert.ToInt32(Interaction.InputBox("Enter eno:", "Search", "20 ", 100, 100));DataRow drow;if (drow != null)null;if (drow[3] != System.DBNull.Value)byte[])drow[3];MemoryStream ms = new MemoryStream(photo_aray);Image.FromStream(ms);else


}


MessageBox.Show("Record Not Found"); catch

{


}

}


{


cmd =

cmd.CommandType =

cmd.Parameters.AddWithValue(

cmd.Parameters.AddWithValue(

cmd.Parameters.AddWithValue(


conv_photo();

con.Open();


con.Close();


{


loaddata();

}


MessageBox.Show("Invalid Input");private void button8_Click(object sender, EventArgs e)new SqlCommand("update_emp", con);CommandType.StoredProcedure;"@eno", textBox1.Text);"@ename", textBox2.Text);"@gender", comboBox1.Text);int n = cmd.ExecuteNonQuery();if (n > 0)MessageBox.Show("Record Updated");else


}




{


cmd =

cmd.CommandType =

cmd.Parameters.AddWithValue(

con.Open();



{

loaddata();

eno = 0;

showdata();


con.Close();

}


MessageBox.Show("Updation Failed");private void button10_Click(object sender, EventArgs e)new SqlCommand("delete_emp", con);CommandType.StoredProcedure;"@eno", textBox1.Text);int n = cmd.ExecuteNonQuery();if (n > 0)MessageBox.Show("Record Deleted");else

{


}


}


{


{

eno++; showdata();

}


MessageBox.Show("Deletion Failed");private void button4_Click(object sender, EventArgs e)if (eno < ds.Tables[0].Rows.Count - 1)else

{


}


}


{


{

eno--; showdata();

}


MessageBox.Show("Last record");private void button3_Click(object sender, EventArgs e)if (eno > 0)else


}


{

eno = ds.Tables[0].Rows.Count - 1;

showdata();

}


{

eno = 0; showdata();


}


{


}


MessageBox.Show("First record");private void button5_Click(object sender, EventArgs e)MessageBox.Show("Last record");private void button2_Click(object sender, EventArgs e)MessageBox.Show("First record");private void button11_Click(object sender, EventArgs e)this.Close();//public string filename { get; set; }

}

}