Hi everyone,
The above error is showing while executing the INSERT query. I have given the code below.
try
{
string desc, aType, loc, manuf, bay, model, condtn, vendor, notes, status;
int serialNo, aCode;
DateTime warrantyExpiry, dateOfPurchase;
desc = Convert.ToString(textBoxDesc.Text);
aType = Convert.ToString(comboBoxAType.SelectedItem);
loc = Convert.ToString(comboBoxLocation.SelectedItem);
manuf = Convert.ToString(textBoxManuf.Text);
bay = Convert.ToString(textBoxBay.Text);
model = Convert.ToString(textBoxModel.Text);
condtn = Convert.ToString(comboBoxCondition.SelectedItem);
vendor = Convert.ToString(comboBoxVendor.SelectedItem);
notes = Convert.ToString(textBoxNotes.Text);
status = Convert.ToString(comboBoxStatus.SelectedItem);
warrantyExpiry = dateTimePickerWarranty.Value.Date;
dateOfPurchase = dateTimePickerDOP.Value.Date;
serialNo = Convert.ToInt32(textBoxSerialNo.Text);
if (rdBtnAutomatic.Checked == true)
{
aCode = 123;
textBoxAcode.ReadOnly=true;
}
else if (rdBtnManual.Checked == true)
{
textBoxAcode.ReadOnly = false;
textBoxAcode.BackColor = Color.White;
aCode = Convert.ToInt32(textBoxAcode.Text);
}
else { aCode = 1; }
con.Open();
OleDbCommand cmd = new OleDbCommand("INSERT INTO Assets(Description,AssetType,Location,Manufacturer,Bay,Model,SerialNumber,Status,Condition,WarrantyExpiry,AssetCode,Dateofpurchase,Vendor,Notes,Picture) VALUES(@Description,@AssetType,@Location,@Manufacturer,@Bay,@Model,@SerialNumber,@Status,@Condition,@WarrantyExpiry,@AssetCode,@Dateofpurchase,@Vendor,@Notes,@Picture)", con);
MemoryStream memoryStream = new MemoryStream();
pictureBoxAssets.Image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imgArray = new byte[memoryStream.Length];
memoryStream.Read(imgArray, 0, imgArray.Length);
cmd.Parameters.AddWithValue("@Description", desc);
cmd.Parameters.AddWithValue("@AssetsType", aType);
cmd.Parameters.AddWithValue("@Location", loc);
cmd.Parameters.AddWithValue("@Manufacturer", manuf);
cmd.Parameters.AddWithValue("@Bay", bay);
cmd.Parameters.AddWithValue("@Model", model);
cmd.Parameters.AddWithValue("@SerialNumber", serialNo);
cmd.Parameters.AddWithValue("@Status", status);
cmd.Parameters.AddWithValue("@Condition", condtn);
cmd.Parameters.AddWithValue("@WarrantyExpiry", warrantyExpiry);
cmd.Parameters.AddWithValue("@AssetCode",aCode);
cmd.Parameters.AddWithValue("@Dateofpurchase", dateOfPurchase);
cmd.Parameters.AddWithValue("@Vendor", vendor);
cmd.Parameters.AddWithValue("@Notes", notes);
cmd.Parameters.AddWithValue("@Picture", imgArray);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
MessageBox.Show("Successfull");
}
else
MessageBox.Show("Notsuccessfull");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Pls help me with this error. Thanks.