2 Replies - 1543 Views - Last Post: 23 June 2012 - 07:25 PM Rate Topic: -----

#1 TemplarBlade22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 16-June 12

Homework: VB2010 Database 1:Many Relationship Problem

Posted 23 June 2012 - 03:49 PM

I am trying to run an inventory program and as you can see below it is very rough. The program pulls data from three tables in a database. The main problem that I am encountering is that the ORDER.itemID and INVENT.itemID do not have a 1:1 relationship. I need to have the ORDER.quantity fields add together for identical itemID's. Unfortunately my book doe not give any examples and the teacher is a hermit or something.

The other problem I am having is that when it does display it shows a line like this

{itemID = SW934, NewOrder = 5, Description = T-Shirt Maker}

I am not sure how to make it display like "SW934 5 T-Shirt Maker" in the lstDisplay listbox.

Public Class frmAssignment_9

    Private Sub btnStock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStock.Click
        Dim QueryStock = From INVENT In _MICROLAND_1_DataSet.Inventory
                         Join ORDER In _MICROLAND_1_DataSet.Orders
                         On INVENT.itemID Equals ORDER.itemID
                         Where INVENT.quantity < ORDER.quantity
                         Let NewOrder = ORDER.quantity - INVENT.quantity
                         Select INVENT.itemID, NewOrder, INVENT.description

        lstDisplay.DataSource = QueryStock.ToList

        

    End Sub

    Private Sub frmAssignment_9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the '_MICROLAND_1_DataSet.Customers' table. You can move, or remove it, as needed.
        Me.CustomersTableAdapter.Fill(Me._MICROLAND_1_DataSet.Customers)
        'TODO: This line of code loads data into the '_MICROLAND_1_DataSet.Inventory' table. You can move, or remove it, as needed.
        Me.InventoryTableAdapter.Fill(Me._MICROLAND_1_DataSet.Inventory)
        'TODO: This line of code loads data into the '_MICROLAND_1_DataSet.Orders' table. You can move, or remove it, as needed.
        Me.OrdersTableAdapter.Fill(Me._MICROLAND_1_DataSet.Orders)

    End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Homework: VB2010 Database 1:Many Relationship Problem

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10767
  • View blog
  • Posts: 40,090
  • Joined: 27-December 08

Re: Homework: VB2010 Database 1:Many Relationship Problem

Posted 23 June 2012 - 04:37 PM

Moved to VB.NET. Please don't post programming questions in the student campus.
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1062
  • View blog
  • Posts: 4,137
  • Joined: 02-July 08

Re: Homework: VB2010 Database 1:Many Relationship Problem

Posted 23 June 2012 - 07:25 PM

If you like LINQ and lambda based queries Entity Framework was made for you. Way easy to set up since your database is already made. For your situation you make a custom class with those properties and fill it with a query and then Override the ToString fucntion of that class and the listbox will display based on the ToString you return.

Public Overrides Function ToString() As String
  Return String.Format("{0} {1} {2}", itemId, NewOrder, description)
End Function


I have not tested this with Entity yet, but that is how the Listbox knows what to display when it contains objects other than Strings.

This post has been edited by _HAWK_: 23 June 2012 - 07:26 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1