string connectionString = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\nic-15\My Documents\ALRS.mdb");
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
string query = "insert into arms_records (licence_category,transfer_state,transfer_district,transfer_place,thana,licence_number,sanction_date,renewal_date,licencee_name,father_name,dob,age,religion,category,address,village,vid,mobile,profession,arms_category,type_of_arm,riv_pistol,no_of_arms,arms_number,valid_area,remark,add_remark,can_date,[image],[arms_image]) values (@lcat, @tstate, @tdistrict, @tplace, @thana, @lno, @sdate, @rdate, @lname, @fname, @dob, @age, @religion, @category, @address, @village, @vid, @mobile, @profession, @armscat, @toarm, @rivpis, @narms, @ano, @varea, @remark, @addremark, @candate, @image, @armsImage)";
OleDbCommand cmd = new OleDbCommand(query, con);
cmd.Parameters.AddWithValue("@lcat", comboBoxLicenceCategory.SelectedText);
//if (comboBoxLicenceCategory.SelectedIndex == 4)
//{
// cmd.Parameters.AddWithValue("@tstate", comboBoxDistrict.SelectedItem);
// cmd.Parameters.AddWithValue("@tdistrict", ".");
//}
//else if (comboBoxLicenceCategory.SelectedIndex == 5)
//{
// cmd.Parameters.AddWithValue("@tstate", comboBoxState.SelectedItem);
// cmd.Parameters.AddWithValue("@tdistrict", textBoxPlace.Text);
//}
//else
//{
cmd.Parameters.AddWithValue("@tstate", comboBoxState.SelectedText);
cmd.Parameters.AddWithValue("@tdistrict",comboBoxDistrict.SelectedItem);
//}
cmd.Parameters.AddWithValue("@tplace", textBoxPlace.Text);
cmd.Parameters.AddWithValue("@thana", comboBoxthana.SelectedItem);
cmd.Parameters.AddWithValue("@lno", textBoxLicence_number.Text);
cmd.Parameters.AddWithValue("@sdate", dateTimePicker1.Text);
cmd.Parameters.AddWithValue("@rdate", dateTimePickerRenewDate.Text);
cmd.Parameters.AddWithValue("@lname", textBoxLicencee_Name.Text);
cmd.Parameters.AddWithValue("@fname", textBoxFatherName.Text);
cmd.Parameters.AddWithValue("@dob", dateTimePickerDob.Text);
cmd.Parameters.AddWithValue("@age", textBoxAge.Text);
cmd.Parameters.AddWithValue("@religion", comboBoxReligion.SelectedItem);
cmd.Parameters.AddWithValue("@category", comboBoxCaste.SelectedItem);
cmd.Parameters.AddWithValue("@address", textBoxAdress.Text);
cmd.Parameters.AddWithValue("@village", textBoxvillage.Text);
cmd.Parameters.AddWithValue("@vid", textBoxUid.Text);
cmd.Parameters.AddWithValue("@mobile", textBox1Mobile.Text);
cmd.Parameters.AddWithValue("@profession", comboBoxProfession.SelectedItem);
cmd.Parameters.AddWithValue("@armscat", comboBoxArmsCategory.SelectedItem);
cmd.Parameters.AddWithValue("@toarm", comboBoxtypeofarm.SelectedItem);
cmd.Parameters.AddWithValue("@rivpis", comboBoxRevPistol.SelectedItem);
cmd.Parameters.AddWithValue("@narms", textBoxNoOfArm.Text);
cmd.Parameters.AddWithValue("@ano", textBoxArmsNo.Text);
cmd.Parameters.AddWithValue("@varea", comboBoxValidArea.SelectedItem);
cmd.Parameters.AddWithValue("@remark", comboBoxRemark.SelectedItem);
cmd.Parameters.AddWithValue("@addremark", textBoxAddRemark.Text);
cmd.Parameters.AddWithValue("@candate", dateTimePickercansus.Text);
// below 10 lines convert image into binary data
byte[] FileByte = null;
//string filename = textBoxImage.Text.Substring(textBoxImage.Text.LastIndexOf("\\") + 1, textBoxImage.Text.Length - (textBoxImage.Text.LastIndexOf("\\") + 1));
string path = textBoxImage.Text;
FileStream fs = new FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long allbytes = new FileInfo(path).Length;
FileByte = br.ReadBytes((Int32)allbytes);
fs.Close();
fs.Dispose();
br.Close();
//below code convert ArmsImage into binary data
byte[] FileByte2 = null;
string path2 = textBoxArmsImage.Text;
FileStream fs2 = new FileStream(path2, System.IO.FileMode.Open, System.IO.FileAccess.Read);
BinaryReader br2 = new BinaryReader(fs2);
long allbytes2 = new FileInfo(path2).Length;
FileByte2 = br2.ReadBytes((Int32)allbytes);
fs2.Close();
fs2.Dispose();
br2.Close();
cmd.Parameters.AddWithValue("@image", FileByte);
cmd.Parameters.AddWithValue("@armsImage", FileByte2);
cmd.ExecuteNonQuery();
con.Close();
//}
//catch (Exception)
// {
// MessageBox.Show("Please select images to upload");
//MessageBox.Show("Please fill all the fields before saving the record");
//}
// MessageBox.Show("Image inserted successfully");
MessageBox.Show("Record saved successfully. ");
refresh();
this is my code and i am getting an error.
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.