Hye.
I am developing a WinForms application in VS19 using C#.
In one of my forms, I am trying to save data into three different tables through 3 parameterized queries.
I am even using classes also to avoid errors but still, I get a strange statement saying "Incorrect Syntax near ",". ".
I am using a button click event to save data as below.
private void AddCustromerDetailsBtnSave_Click(object sender, EventArgs e)
{
SaveItemData();
}
Here is my code for SaveItemData().
private void SaveItemData()
{
//Getting Data from UI
{
using (SqlConnection sqlCon = new SqlConnection(myconnstring))
{
sqlCon.Open();
string SelectQuery = "Select (Max(item_id) +1) from tbl_items";
SqlCommand Command = new SqlCommand(SelectQuery, sqlCon);
SqlDataReader sdr = Command.ExecuteReader();
if (sdr.Read())
{
try
{
bool success = false;
int val = int.Parse(sdr[0].ToString());
int val2 = int.Parse(CreateItemTextBoxID.Text);
if (val2 > val)
{
ibll.item_aliasname = CreateItemTextBoxAliasName.Text;
ibll.item_barcode = CreateItemTextBoxBarCode.Text;
ibll.item_name = CreateItemTextBoxItemName.Text;
ibll.item_genericname_id = Convert.ToInt32(CreateItemComboBoxGenericName.SelectedValue);
ibll.item_genericname = CreateItemComboBoxGenericName.Text;
ibll.item_manufacturer_id = Convert.ToInt32(CreateItemComboBoxManufacturer.SelectedValue);
ibll.item_manufacturer = CreateItemComboBoxManufacturer.Text;
ibll.item_class_id = Convert.ToInt32(CreateItemComboBoxClass.SelectedValue);
ibll.item_class = CreateItemComboBoxClass.Text;
ibll.item_category_id = Convert.ToInt32(CreateItemComboBoxCategory.SelectedValue);
ibll.item_category = CreateItemComboBoxCategory.Text;
ibll.item_location_id = Convert.ToInt32(CreateItemComboBoxLocation.SelectedValue);
ibll.item_location = CreateItemComboBoxLocation.Text;
ibll.item_pieces_in_packing = int.Parse(CreateItemTextBoxPIP.Text);
ibll.item_packing_desc_id = Convert.ToInt32(CreateItemComboBoxPackingDesc.SelectedValue);
ibll.item_packing_desc = CreateItemComboBoxPackingDesc.Text;
ibll.item_pack_purchase_price = Convert.ToDecimal(CreateItemTextBoxPPrice.Text);
ibll.item_unit_purchase_price = Convert.ToDecimal(CreateItemTextBoxUPPrice.Text);
ibll.item_pack_mrp = Convert.ToDecimal(CreateItemTextBoxPRPrice.Text);
ibll.item_unit_mrp = Convert.ToDecimal(CreateItemTextBoxURPrice.Text);
ibll.item_reg_num = CreateItemTextBoxRegNum.Text;
ibll.item_packsalestax = Convert.ToDecimal(CreateItemTextBoxPST.Text);
ibll.item_created_by_id = 1;
ibll.item_created_by = CreateItemTextBoxCreatedBy.Text ?? "Aamir";
ibll.item_created_datetime = DateTime.Now;
isbll.item_id = int.Parse(CreateItemTextBoxID.Text);
isbll.item_name = (CreateItemTextBoxItemName.Text);
isbll.item_active_status = CreateItemCheckBoxActiveStatus.Checked;
isbll.item_printable = CreateItemCheckBoxPrintable.Checked;
isbll.item_generatepo = CreateItemCheckBoxGeneratePO.Checked;
isbll.item_alert_id = Convert.ToInt32(CreateItemComboBoxItemAlerts.SelectedValue);
isbll.item_alert_name = CreateItemComboBoxItemAlerts.Text;
isbll.item_max_sale_disc_percent = Convert.ToDecimal(CreateItemTextBoxMSD.Text);
isbll.item_pack_sale_price = decimal.Parse(CreateItemTextBoxPSPrice.Text);
isbll.item_unit_sale_price = decimal.Parse(CreateItemTextBoxUSPrice.Text);
isbll.item_allowdue = CreateItemCheckBoxAllowDue.Checked;
isbll.item_optimum_quantity = Convert.ToDecimal(CreateItemTextBoxOptimumQty.Text);
isbll.item_minimum_quantity = Convert.ToDecimal(CreateItemTextBoxMinimumQty.Text);
isbll.item_reorder_quantity = Convert.ToDecimal(CreateItemTextBoxReorderQty.Text);
isbll.item_settings_created_by_id = 1;
isbll.item_settings_created_by = "Aamir";
isbll.item_settings_created_datetime = DateTime.Now;
bool a = idal.CreateNewItem(ibll);
bool b = isdal.CreateNewItemSettings(isbll);
foreach (DataGridViewRow dgvRow in CreateItemDataGridViewSuppliers.Rows)
{
if (dgvRow.IsNewRow)
{
break;
}
else
{
ibll.item_id = int.Parse(CreateItemTextBoxID.Text);
int suppid = Convert.ToInt32(dgvRow.Cells["SuppDGVSuppliers"].Value);
ibll.supp_id = suppid;
itemBLL si = idal.SelectSupplierNameByID(suppid);
ibll.item_supp_name = si.item_supp_name;
ibll.item_supp_priority = Convert.ToInt32(dgvRow.Cells["SuppDGVPriority"].Value);
ibll.item_supp_qty = Convert.ToDecimal(dgvRow.Cells["SuppDGVQty"].Value);
ibll.item_supp_rate = Convert.ToDecimal(dgvRow.Cells["SuppDGVRate"].Value);
ibll.item_supp_discperc = Convert.ToDecimal(dgvRow.Cells["SuppDGVDiscPerc"].Value);
ibll.item_supp_bonus = Convert.ToInt32(dgvRow.Cells["SuppDGVBonus"].Value);
int daysid = Convert.ToInt32(dgvRow.Cells["SuppDGVBookingDays"].Value);
itemBLL di = idal.SelectDaysByID(daysid);
ibll.item_supp_days_id = daysid;
ibll.item_supp_days = di.item_supp_days;
bool c = idal.AddItemSuppliers(ibll);
success = a && b && c;
if (success == true)
{
MetroMessageBox.Show(this, "Item " + CreateItemTextBoxItemName.Text + " Has been added in the Database successfully", "Success", MessageBoxButtons.OK, 100);
ClearForm();
CreateItemTextBoxItemName.Focus();
}
else
{
MetroMessageBox.Show(this, "Failed To add Item " + CreateItemTextBoxItemName.Text + " In the Database", "Failed", MessageBoxButtons.OK);
}
}
}
}
else
{
ibll.item_id = val2;
ibll.item_aliasname = CreateItemTextBoxAliasName.Text;
ibll.item_barcode = CreateItemTextBoxBarCode.Text;
ibll.item_name = CreateItemTextBoxItemName.Text;
ibll.item_genericname_id = Convert.ToInt32(CreateItemComboBoxGenericName.SelectedValue);
ibll.item_genericname = CreateItemComboBoxGenericName.Text;
ibll.item_manufacturer_id = Convert.ToInt32(CreateItemComboBoxManufacturer.SelectedValue);
ibll.item_manufacturer = CreateItemComboBoxManufacturer.Text;
ibll.item_class_id = Convert.ToInt32(CreateItemComboBoxClass.SelectedValue);
ibll.item_class = CreateItemComboBoxClass.Text;
ibll.item_category_id = Convert.ToInt32(CreateItemComboBoxCategory.SelectedValue);
ibll.item_category = CreateItemComboBoxCategory.Text;
ibll.item_location_id = Convert.ToInt32(CreateItemComboBoxLocation.SelectedValue);
ibll.item_location = CreateItemComboBoxLocation.Text;
ibll.item_pieces_in_packing = int.Parse(CreateItemTextBoxPIP.Text);
ibll.item_packing_desc_id = Convert.ToInt32(CreateItemComboBoxPackingDesc.SelectedValue);
ibll.item_packing_desc = CreateItemComboBoxPackingDesc.Text;
ibll.item_pack_purchase_price = Convert.ToDecimal(CreateItemTextBoxPPrice.Text);
ibll.item_unit_purchase_price = Convert.ToDecimal(CreateItemTextBoxUPPrice.Text);
ibll.item_pack_mrp = Convert.ToDecimal(CreateItemTextBoxPRPrice.Text);
ibll.item_unit_mrp = Convert.ToDecimal(CreateItemTextBoxURPrice.Text);
ibll.item_reg_num = CreateItemTextBoxRegNum.Text;
ibll.item_packsalestax = Convert.ToDecimal(CreateItemTextBoxPST.Text);
ibll.item_created_by_id = 1;
ibll.item_created_by = CreateItemTextBoxCreatedBy.Text ?? "Aamir";
ibll.item_created_datetime = DateTime.Now;
isbll.item_id = int.Parse(CreateItemTextBoxID.Text);
isbll.item_name = (CreateItemTextBoxItemName.Text);
isbll.item_active_status = CreateItemCheckBoxActiveStatus.Checked;
isbll.item_printable = CreateItemCheckBoxPrintable.Checked;
isbll.item_generatepo = CreateItemCheckBoxGeneratePO.Checked;
isbll.item_alert_id = Convert.ToInt32(CreateItemComboBoxItemAlerts.SelectedValue);
isbll.item_alert_name = CreateItemComboBoxItemAlerts.Text;
isbll.item_max_sale_disc_percent = Convert.ToDecimal(CreateItemTextBoxMSD.Text);
isbll.item_pack_sale_price = decimal.Parse(CreateItemTextBoxPSPrice.Text);
isbll.item_unit_sale_price = decimal.Parse(CreateItemTextBoxUSPrice.Text);
isbll.item_allowdue = CreateItemCheckBoxAllowDue.Checked;
isbll.item_optimum_quantity = Convert.ToDecimal(CreateItemTextBoxOptimu
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…