private void itemRowUpdated(object sender, OleDbRowUpdatedEventArgs e) { if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) { long maxId = DBUtil.GetMaxIDWithConnection("Type_ID", "ItemType", e.Command.Connection); ShopDAL.insertValueOfStockInHand(e.Command.Connection, maxId); } }
public static bool InsertNewItemType(ItemType item) { //Create the objects we need to insert a new record OleDbConnection cnInsert = new OleDbConnection(DBUtil.GetConnectionString()); OleDbCommand cmdInsert = new OleDbCommand(); string query = " INSERT INTO ItemType(Name,Price, Sale_Price, UoM_ID, Vendor_ID) "; query += " VALUES(@name, @price, @salePrice, @uomId, @vendorId)"; int iSqlStatus; //Clear any parameters cmdInsert.Parameters.Clear(); try { //Set the OleDbCommand Object Properties //Tell it what to execute cmdInsert.CommandText = query; //Tell it its a text query cmdInsert.CommandType = CommandType.Text; //Now add the parameters to our query //NOTE: Replace @value1.... with your parameter names in your query //and add all your parameters in this fashion cmdInsert.Parameters.AddWithValue("@name", item.ItemName); cmdInsert.Parameters.AddWithValue("@price", item.Price); cmdInsert.Parameters.AddWithValue("@salePrice", item.SalePrice); cmdInsert.Parameters.AddWithValue("@uomId", item.Uom.Id); cmdInsert.Parameters.AddWithValue("@vendorId", item.Vendor.Id); //Set the connection of the object cmdInsert.Connection = cnInsert; //Now take care of the connection DBUtil.HandleConnection(cnInsert); //Set the iSqlStatus to the ExecuteNonQuery //status of the insert (0 = failed, 1 = success) iSqlStatus = cmdInsert.ExecuteNonQuery(); //Now check the status if (iSqlStatus == 0) { return(false); } else { return(true); } } catch (Exception ex) { return(false); } finally { //Now close the connection DBUtil.HandleConnection(cnInsert); long maxId = DBUtil.GetMaxID("Type_ID", "ItemType"); ShopDAL.insertValueOfStockInHand(cnInsert, maxId); } }