private void btn_item_transfer_Click(object sender, EventArgs e) { if (cbo_table_no_choose.Text != "Choose One" && cbo_table_no_choose.SelectedIndex > 0 && cbo_table_no_choose.Text != "") { if (dataGridView2.Rows.Count > 0) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { string order_id = dataGridView1.Rows[i].Cells["cal_order_id"].Value.ToString(); string qty = dataGridView1.Rows[i].Cells["cal_qty"].Value.ToString(); string total = dataGridView1.Rows[i].Cells["cal_total"].Value.ToString(); string status = dataGridView1.Rows[i].Cells["cal_status"].Value.ToString(); if (status == "Update") { int update = blo.updateorderstable(Convert.ToDecimal(qty), Convert.ToInt32(order_id), Convert.ToDecimal(total)); //this stattement will update the item of datagridview1 } } for (int i = 0; i < dataGridView2.Rows.Count; i++) { string order_id = dataGridView2.Rows[i].Cells["cal_order_id_2"].Value.ToString(); string qty = dataGridView2.Rows[i].Cells["cal_qty_2"].Value.ToString(); string total = dataGridView2.Rows[i].Cells["cal_total_2"].Value.ToString(); string category_name = dataGridView2.Rows[i].Cells["cal_category_name2"].Value.ToString(); string kot_type = dataGridView2.Rows[i].Cells["cal_kot_type_2"].Value.ToString(); string item_name = dataGridView2.Rows[i].Cells["cal_item_name2"].Value.ToString(); string cost = dataGridView2.Rows[i].Cells["cal_cost_2"].Value.ToString(); string status = dataGridView2.Rows[i].Cells["cal_status_2"].Value.ToString(); string table_no = cbo_table_no_choose.SelectedValue.ToString(); if (status == "I") { //DataTable dt = blo.getallbyitem_nameandTableno(item_name, table_no); //if (dt.Rows.Count == 0) //{ int insert_order = blo.insertorder_using_sp(Login.sendtext, Convert.ToDecimal(table_no), item_name, Convert.ToDecimal(qty), Convert.ToDecimal(total), Convert.ToDecimal(cost), "Y", category_name, kot_type, "TS", "0", 0); //this will insert data of datagridview2 if (dataGridView2.Rows[i].Cells["cal_delete_status"].Value.ToString() == "True") { int delete_item = blo.deletefromorder_id(Convert.ToInt32(order_id)); } //else //{ //int updateOrder = blo.updateorderItemTransfer(Convert.ToInt32(order_id), Convert.ToDecimal(table_no)); // } } else { int updateOrder = blo.updateorderItemTransfer(Convert.ToInt32(order_id), Convert.ToDecimal(table_no));//this will update datagridview2 } } this.Close(); } else { MessageBox.Show("There is no data to transfer.", "Invalid Item Transfer", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Choose Correct Table No.", "Invalid Table No", MessageBoxButtons.OK, MessageBoxIcon.Error); } }