简体   繁体   English

如何从MS Access获取数据到ListView VB6

[英]How to get data from MS Access to listview VB6

I have data in listview VB6 like this. 我在这样的Listview VB6中有数据。

VB6中的Listview

and this is the coding for insert data to my listview from textbox "Receivedata" 这是将数据从文本框“ Receivedata”插入到我的列表视图中的编码

Private Sub AddList_Click()  
Dim i As Long
Dim sLines() As String
Dim sValues() As String
Dim oItem As ListItem

sLines() = Split(receivedata.Text, vbCrLf)
For i = 0 To UBound(sLines)
   If sLines(i) > vbNullString Then ' skip for empty line
      sValues() = Split(sLines(i), ".")

      Set oItem = ListView1.ListItems.Add(, , sValues(0))
      Call oItem.ListSubItems.Add(, , sValues(1))
      Call oItem.ListSubItems.Add(, , sValues(2))
   End If
Next i
End Sub

and this is my database in ms access: 这是我在ms access中的数据库:

数据库

i want to get data "Product_Name" and "Price" from ms access by matching the barcode's data. 我想通过匹配条形码的数据来从ms访问中获取数据“ Product_Name”和“ Price”。

how to connect the ms access with VB6 and get thedata from ms access to my listview? 如何将ms访问与VB6连接并从ms访问获取数据到我的列表视图? i builded connection from ADODC like this: 我从ADODC建立了这样的连接:

在此处输入图片说明

please help me.. 请帮我..

The simplest possible approach: once you have successfully connected to your database table, You may use the (almost forgotten) Filter property of the ADODB.Recordset . 最简单的方法:成功连接到数据库表后,就可以使用ADODB.Recordset的(几乎被遗忘) Filter属性。

Inside the loop of your received data, you should restrict the price master data of your product to just only the one row you need: 在收到的数据循环中,应将产品的价格主数据 限制为仅需要的一行

Adodc1.Recordset.Filter = "Barcode = '" & sValues(1) & "'"

Then, depending from your connection string, you may find the product name and price inside the Recordset Fields collection. 然后,根据您的连接字符串,您可以在Recordset Fields集合内找到产品名称和价格。 For example: 例如:

ProductName = Adodc1.Recordset.Fields("Product_Name")
Price = Adodc1.Recordset.Fields("Price")

Additional information: 附加信息:

As your question is somewhat broader than just only the ADO Data Control, an additional discussion is required. 由于您的问题比仅仅ADO Data Control还要广泛,因此需要进行其他讨论。 I'm posting the discussion here, because it doesn't fit inside a comment. 我在此处发布讨论,因为它不适合评论。

You should think about the questions below and try to get an answer by yourself. 您应该考虑以下问题,并尝试自己获得答案。

Premise: from the screenshot of your Products Table, it seems to me you have defined the autoincrement Number field as Primary Key. 前提:从“产品表”的屏幕快照中,在我看来,您已经将“自动递增Number字段定义为“主键”。

Q: How can you be sure, when you apply the Filter , that there will be just only one row for each Barcode? 问:当应用“ Filter ,如何确定每个条形码只有一行? Is there in your database table a constraint which can avoid such a scenario? 数据库表中是否存在可以避免这种情况的约束?

Q: What happened, and what action you should undertake if you find two rows with different prices? 问:发生了什么?如果发现两行价格不同,应该采取什么措施?

Below are the Fields from the Price List table of a popular international ERP software: 以下是流行的国际ERP软件的价格表中的字段:

  • Product Code 产品代码
  • Customer Code 客户代码
  • Product Group 产品组
  • Customer Group 客户群
  • Currency Code 货币代码
  • Minimum Quantity 最小用量
  • Starting Date 开始日期
  • Ending Date 结束日期
  • Price (Local Currency) 价格(当地货币)
  • Price (Foreign Currency) 价格(外币)
  • Barcode 条码

Q: what are the fields of the Primary Key? 问:主键的字段是什么?

Q: why isn't the field Product Name inside this table? 问:为什么表中没有“ 产品名称 ”字段?

Q: Why isn't the field Ending Date in the Primary Key? 问:为什么主键中的“ 结束日期 ”字段没有显示?

Q: How many Foreign Keys exists in the database, which are related to this Price List table? 问:数据库中存在多少与此价目表相关的外键?

Q: Why there is another Barcode field in the Product table, but doesn't contain the same data? 问:为什么“ 产品”表中还有另一个“条形码”字段,但没有包含相同的数据?

Happy learning! 学习愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM