pls, educate me!
"WHERE are am I wrong? the problem is at the "UPDATE " line. my "insert " snippet code is good and working. but UPDATE is throwing an Error : Syntax Error at Update Statement
see the code below :
private void btnInsert_Click(object sender, EventArgs e)
{
cmd = new OleDbCommand("insert into PersInfo values(" + textBox4.Text + ",' " + comboBox5.SelectedItem + "',' " +
textBox10.Text + "',' " + textBox1.Text + "',' " + textBox2.Text + "',' " + comboBox1.SelectedItem + "',' " +
textBox12.Text + "',' " + textBox11.Text + "',' " + textBox5.Text + "',' " + textBox7.Text + "',' " +
textBox13.Text + "',' " + textBox6.Text + "',' " + comboBox3.SelectedItem + "',' " + comboBox2.SelectedItem + "',' " +
comboBox4.SelectedItem + "',' " + textBox15.Text + "',' " +
textBox9.Text + "',@susptpic, @victmpic)", con);
conv_photo();
con.Open();// connection from c# to dataset table (PersInfo) of the ms access database
int n = cmd.ExecuteNonQuery();
con.Close();
if (n > 0)
{
MessageBox.Show("Record Inserted");
loaddata();
}
else
MessageBox.Show("Insertion Failed");
}
void conv_photo()
{
//converting photo into binary
//for pic2 only
if (pictureBox2.Image != null)
{
//using memory stream:
ms = new MemoryStream();
pictureBox2.Image.Save(ms, ImageFormat.Jpeg);
byte[] photo_array = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_array, 0, photo_array.Length);
cmd.Parameters.AddWithValue("@susptpic", photo_array);
}
//for pic 1
if (pictureBox1.Image != null)
{
//using memory stream:
ms2 = new MemoryStream();
pictureBox1.Image.Save(ms2, ImageFormat.Jpeg);
byte[]photo2_array = new byte[ms2.Length];
ms2.Position = 0;
ms2.Read(photo2_array,0, photo2_array.Length);
cmd.Parameters.AddWithValue("@victmpic", photo2_array);
}
}
private void btnUpdate_Click(object sender, EventArgs e)// UPDATE BUTTON
{
cmd = new OleDbCommand("update PersInfo set infotype='" + comboBox5.SelectedItem +
"' ,firstname='" + textBox10.Text + "',othernames='" + textBox1.Text +
"' ,address='" + textBox2.Text + "',casetype='" + comboBox1.SelectedItem +
"' ,email='" + textBox12.Text + "',phoneno='" + textBox11.Text +
"' ,occupatn='" + textBox5.Text + "',national='" + textBox7.Text +
"' ,dateofbirth='" + textBox13.Text + "',lgarea='" + textBox6.Text +
"',status='" + comboBox3.SelectedItem + "',educatn='" + comboBox2.SelectedItem +
"',deceased='" + comboBox4.SelectedItem + "',datedeceased='" + textBox15.Text +
"',comments='" + textBox9.Text + "' , photo=@susptpic, photo2=@victmpicwhere sno=" + textBox4.Text, con);
con.Open();// connection from c# to dataset table (PersInfo) of the ms access database
conv_photo();
int n = cmd.ExecuteNonQuery();
con.Close();
if (n > 0)
{
MessageBox.Show("Record Updated");
loaddata();
}
else
MessageBox.Show("Update Failed");
}