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);
}

Michal HabalcikRank #902 · 2.3K reputationPosted Dec 22, 2014, 6:57 AM EST
string sql = "SET IDENTITY_INSERT studentregister ON;
INSERT INTO my_table_name (sid,fname,lastname,address,email,contact,payment,image)VALUES(" + sid.Text + ",'" + sfn.Text + "','" + sln.Text + "','" + ad.Text + "','" + mail.Text + "','" + ct.Text + "','" + pn.Text + "',@img)";
Sathishka Priyad5 reputationPosted Dec 22, 2014, 7:00 AM EST
Sathishka Priyad5 reputationPosted Dec 22, 2014, 7:02 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 22, 2014, 7:22 AM EST
Khargesh RajputRank #616 · 3.9K reputationPosted Dec 22, 2014, 6:00 PM EST
your sid column is integer so you have to convert it into integer
also add insert tablename
As michal Replied..
INSERT INTO my_table_name
(sid,fname,lastname,address,email,contact,payment,image)VALUES(" + convert.toint32(sid.Text) + ",'" + sfn.Text + "','" + sln.Text + "','" + ad.Text + "','" + mail.Text + "','" + ct.Text + "','" + pn.Text + "',@img)";