In this Post How to Delete Registration Form with Profile Image Asp.Net
Important Namespaces Used ------------------------------ using System.Data; using System.Data.SqlClient; ------------------------------ Static Variable Declaration ------------------------------ static String imagelink; ------------------------------ Search Button Click Event ------------------------------ String mycon = "Data Source=sk-pc; Initial Catalog=Class-College-Database; Integrated Security=True"; String myquery = "Select * from profiledetail where rollno=" + TextBox1.Text; SqlConnection con = new SqlConnection(mycon); SqlCommand cmd = new SqlCommand(); cmd.CommandText = myquery; cmd.Connection = con; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { Label4.Text = "Particular Roll Number Found"; TextBox2.Text = ds.Tables[0].Rows[0]["sname"].ToString(); TextBox3.Text = ds.Tables[0].Rows[0]["fname"].ToString(); TextBox4.Text = ds.Tables[0].Rows[0]["mname"].ToString(); imagelink = ds.Tables[0].Rows[0]["profileimage"].ToString(); Image1.ImageUrl = imagelink+ "?n=" + DateTime.Now.Second.ToString(); } else { Label4.Text = "Particular Roll Number Not Found"; } con.Close(); ------------------------------ Delete Button Click Event Coding ---------------------------------- String mycon = "Data Source=sk-pc; Initial Catalog=Class-College-Database; Integrated Security=True"; String updatedata = "delete from profiledetail where rollno=" + TextBox1.Text; SqlConnection con = new SqlConnection(mycon); con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = updatedata; cmd.Connection = con; cmd.ExecuteNonQuery(); Label5.Text = "Particular Searched Rollno Has Been Deleted"; System.IO.File.Delete(Server.MapPath(imagelink)); -----------------------------------