try
{
byte[] img = null;
FileStream fs = new FileStream(imgLoc, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
img = br.ReadBytes((int)fs.Length);
string sql = "SET IDENTITY_INSERT studentregister ON;(sid,fname,lastname,address,email,contact,payment,image)VALUES(" + sid.Text + ",'" + sfn.Text + "','" + sln.Text + "','" + ad.Text + "','" + mail.Text + "','" + ct.Text + "','" + pn.Text + "',@img)";
if (con.State != ConnectionState.Open)
con.Open();
command = new SqlCommand(sql,con);
command.Parameters.Add(new SqlParameter("@img", img));
int x = command.ExecuteNonQuery();
con.Close();
MessageBox.Show(x.ToString() + "Record Saved");
}
catch (Exception ex) {
con.Close();
MessageBox.Show(ex.Message);
}