- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一组订单,每个订单都有所需的重量,还有一组火鸡,每个都有重量,所有这些都包含在数据库和数据集中,但通过对象访问(这使它变得更复杂,但对象是那里增加了项目的复杂性,而不是因为这是一个好主意)。
如何匹配它们,然后更新数据库和数据集?我正在尝试使用列表和 LINQ 来完成它,但效果不佳。不幸的是,我看不出哪里出错了。编辑:线 For Count = 0 To Max - 1
出现索引越界错误。我知道这意味着什么,但我不明白我为什么会收到它,以及如何解决它。
Orders.UpdateOrder(Count, Count + 1, Orders.OrderDetail(Count, "CustomerID"), TurkeyList(Count)(0), Orders.OrderDetail(Count, "ApproxWeight"))
Next
我已经完成了我的研究 - 事实上,我目前的尝试使用列表(我从未听说过,直到我在 StackOverflow 上看到我可以使用它们)但是,老实说,这不是我一直在做的事情教导,我可以使用一些指导。我最初尝试使用二维数组,但没有用。我认为我当前的实现应该有效——所以我很有可能只是遗漏了一些愚蠢的东西。以下是我的代码的相关部分。
Imports System.Linq
# <summary>
# SortForm is a public class which handles the events and controls of a single form.
# </summary>
# <remarks></remarks>
Public Class SortForm
Dim Turkeys As New TurkeyDBInteract
Dim Orders As New OrderDBInteract
Dim Customers As New CustomerDBInteract
Public TurkeyList As New List(Of Integer())
Public OrderList As New List(Of Integer())
# <summary>
# The FillLists subroutine fills the two lists with data from the dataset.
# </summary>
# <remarks></remarks>
Public Sub FillLists()
For Count = 0 To Orders.OrderNum - 1
OrderList.Add(New Integer() {Count, Orders.OrderDetail(Count, "ApproxWeight")})
Next
For Count = 0 To Turkeys.TurkeyNum - 1
TurkeyList.Add(New Integer() {Count, Turkeys.TurkeyDetail(Count, "Weight")})
Next
End Sub
# <summary>
# The SortList subroutine takes a List of 1-dimensional integer and sorts it using LINQ to Objects.
# </summary>
# <param name="List"></param>
# <remarks></remarks>
Public Sub SortList(ByRef List As List(Of Integer()))
Dim SortedList As New List(Of Integer())
SortedList = List.OrderBy(Function(Weight) Weight(1)).ToList()
List = SortedList
End Sub
# <summary>
# This is the SortButton click event. This calls the <see cref="FillLists"/> and <see cref="SortList"/> subroutines to process order and turkey data, then matches the lists and uses this to update the dataset and database.
# </summary>
# <param name="sender"></param>
# <param name="e"></param>
# <remarks></remarks>
Private Sub SortButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SortButton.Click
FillLists()
SortList(TurkeyList)
SortList(OrderList)
Dim Max As Integer
If TurkeyList.Count > OrderList.Count Then
Max = OrderList.Count
Else
Max = TurkeyList.Count
End If
For Count = 0 To Max - 1
Orders.UpdateOrder(Count, Count + 1, Orders.OrderDetail(Count, "CustomerID"), TurkeyList(Count)(0), Orders.OrderDetail(Count, "ApproxWeight"))
Next
End Sub
End Class
这是 OrderDBInteract 类中 OrderUpdate 方法的代码
# <summary>
# Subroutine UpdateOrder updates every value of a specific record of the OrderTbl dataset table and then updates the database.
# </summary>
# <param name="Row">Row passes the row of the record to be updated.</param>
# <param name="OrderID">OrderID passes the new primary key value of the record to be updated.</param>
# <param name="CustomerID">CustomerID passes the new foreign key field value of the record to be updated.</param>
# <param name="ApproxWeight">ApproxWeight passes a new field value of the record to be updated.</param>
# <remarks></remarks>
Public Sub UpdateOrder(ByVal Row, ByVal OrderID, ByVal CustomerID, ByVal TurkeyID, ByVal ApproxWeight)
Data.Tables("OrderTbl").Rows(Row).Item("OrderID") = OrderID
Data.Tables("OrderTbl").Rows(Row).Item("CustomerID") = CustomerID
Data.Tables("OrderTbl").Rows(Row).Item("TurkeyID") = TurkeyID
Data.Tables("OrderTbl").Rows(Row).Item("ApproxWeight") = ApproxWeight
End Sub
最佳答案
试试sortedlist根据键对值进行排序。例如:
Dim OrderList As New SortedList
For Count = 0 To Orders.OrderNum - 1
OrderList.Add(Orders.OrderDetail(Count, "ApproxWeight"), Count)
Next
将根据 Orders.OrderDetail 的结果对值 (Count) 进行排序。这样您就不需要调用 SortList 方法。
虽然,这
Data.Tables("OrderTbl").Rows(Row).Item("OrderID") = OrderID
确实更改了数据集表中行的 OrderID 列值,这些更改不会提交到数据库。看看这个msdn walkthrough关于将数据保存到数据库。基本上,您需要一个具有适当 UpdateCommand 设置的 DataAdapter,以使用来自数据集的更改来更新数据库表。如果您在程序中使用类型化数据集,那么将更改提交到数据库将变得更加容易。
关于database - 如何将订单与产品匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15079681/
我需要按不同类别过滤我网站上的产品。例如,如果您选择“DRINKS”类别,它将向我显示属于该类别的产品。 为了更好地解释自己。 我需要按类别过滤我网站的出版物 [产品],例如,在选择一个类别时说“饮料
我有 orders 集合,其中包含 products 集合。我将一些产品 ID 作为列表传递给该方法。我需要返回与任何匹配的产品列表input 列表中的 id。 我需要像这样使用 foreach 循环
我已经为临时分发进行存档好几个月了,但今天突然我无法这样做,因为“存档”菜单项已被禁用。我没有改变任何东西。我完成了该项目的配置设置,看起来没问题。 我的临时个人资料即将在 14 天后过期。这可能是问
我正在尝试找出产品和产品属性之间的关系。我有一个 product 表和一个 product_attributes 表。产品可以具有多种属性。我需要查询来查找具有一个特定属性和另一个属性之一的所有产品。
我正在使用 MySQL Workbench 创建 EER 图。 实现产品、类别和公司表之间关系的最佳方式是什么? 我正在考虑这种关系,但考虑到我想让公司的客户管理自己的产品/类别,这是最好的方式吗?如
我正在使用 itertools 包,并尝试在具有 900 个值的数组中创建 1、2 和 3 的所有可能组合,然后将其转换为 30 x 30 矩阵。我必须执行此操作的代码在下面并且工作正常。 for d
我有几个关于 Cartridge 启动器的问题: 我的产品不需要评级或发布日期。他们永远不会出售。一些产品是可下载的,因此“num_in_stock”不相关或本质上是无限制的。没有颜色选项,只有尺寸。
在 MySQL 中,存储产品价格(或一般货币)的首选列类型是什么?谷歌知道我经常使用 DECIMAL of FLOAT,但我想知道哪个更好。 我存储的价格范围是 0.01 到 25.00。当然更高的值
在软件开发过程中,尤其是在准备将新功能或修复后的版本上线之前,进行详尽的自测和上线前检查是至关重要的。以下是一个从多个维度综合考量的上线升级检查清单(Checklist),旨在帮助团队确保软件质量、稳
我正在创建一个闪购网站,并且我已经在主页和商店页面上根据日期范围显示产品。但我也想根据其他地方的日期范围显示产品,因此使用简码。 这是我的代码: function testt($meta_query)
可以在 WooCommerce 上批量创建产品吗?我正在使用 wp-cli Product 命令,但似乎我必须一个一个地创建。 'My product 1'), array('title'
我有一个带有数量和价格列的 excel 文件,我用它来为插件 WooCommerce Dynamic Pricing 创建必要的输出的定价规则。 我几乎想通了,但是 WooCommerce 进口商正在
我刚刚继承了一个woocommerce项目,我需要将主页更改为仅显示特定品牌。他们设置了 Product-Data => Attribute => pa_brand。 如果我打印 pa_brand 数
在插件中如何使用 wc_get_products() 获取产品。或者有其他方法可以做到吗? if ( in_array( 'woocommerce/woocommerce.php', apply_fi
我正在做一个无法从公司网络外部访问的内部网,他们希望在 Plone 中显示一些关于文件下载和最常查看的页面的不错的统计数据。 由于网络限制,我无法使用谷歌分析或任何类型的外部服务,那么是否有任何产品可
我正在就以下问题寻求建议: 保留哪些产品 key 属于哪个客户端的列表。例如,如果我的产品 key 为 8456-7894-4567-7894,则应该这样设计,以便将列表写入数据库而不是文件。 如何将
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
尝试将产品搜索栏添加到 Wordpress 管理栏后端,以进行 Woocommerce 产品搜索。它将位于后端管理菜单栏的顶部,这样无论您在后端的哪个位置,都可以搜索 woo 的产品。我很接近但在小绊
这让我抓狂.. 我正在尝试根据特定属性查询和输出 WooCommerce 产品。例如,我设置了一个名为 on 的属性,可能的值为 yes或 no . 我使用以下查询: $args = array(
我正在尝试从 Shopify 商店获取所有产品的 JSON。我一直在向 {STORE URL}/products.json 端点。但这最终只显示了商店提供的部分产品(很多,但不是全部)。当我将参数更改
我是一名优秀的程序员,十分优秀!