Why does this DataTable have no data in it?

Posted on 2014-07-17
Last Modified: 2014-07-19

Using VS2013 to program a Windows Form application in

Created DataSource which links to an Access mdb database:
Screenshot of Data SourceTbl_Customers has 8,670 records
Tbl_Invoices has 15,512 records

I can see these results using the Preview Data... function associated with each table in the Data Source.  See screenshots at end of post.

Write code to extract data from Tbl_Customers and it returns 8670.  PERFECT.  Code:
Dim myCustomers As DataTable = On_OrderDataSet.Tbl_Customers

Open in new window

Write duplicate code to extract data from Tbl_Invoices and it returns 0.  WRONG!  Code:
Dim myInvoices As DataTable = On_OrderDataSet.Tbl_Invoices

Open in new window

What the heck is going on?  Why won't this data come through?  Please help because it's driving me crazy!

Question by:SqueezeOJ
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2

Author Comment

ID: 40203349
I tried the exact same on four tables using slightly different syntax:
Dim myCategories As DataTable = On_OrderDataSet.Tables("Tbl_Categories")
MsgBox("Category Records = " & myCategories.Rows.Count)

Dim myCustomers As DataTable = On_OrderDataSet.Tables("Tbl_Customers")
MsgBox("Customer Records = " & myCustomers.Rows.Count)

Dim myFabrics As DataTable = On_OrderDataSet.Tables("Tbl_Fabrics")
MsgBox("Fabric Records = " & myFabrics.Rows.Count)

Dim myInvoices As DataTable = On_OrderDataSet.Tables("Tbl_Invoices")
MsgBox("Invoice Records = " & myInvoices.Rows.Count)

Open in new window

The ONLY one that worked correctly was the Customer table.
LVL 14

Expert Comment

ID: 40203471
How / when are you filling the tables with data? Is it after you're calling rows.count?

Author Comment

ID: 40203669
Good question and one I've been pondering.  I don't "fill" any of them, yet one is full of data and the other three are empty.  What statement would you recommend for me to fill them?  Thanks!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 83

Expert Comment

ID: 40204165
Can you show us code from your Form_Load event?

Author Comment

ID: 40204265
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

	' Adding Customer Columns
	lvwCustomers.Columns.Add("CustID", 100, HorizontalAlignment.Left)
	lvwCustomers.Columns.Add("Last", 150, HorizontalAlignment.Left)
	lvwCustomers.Columns.Add("First", 150, HorizontalAlignment.Left)
	lvwCustomers.Columns.Add("City", 150, HorizontalAlignment.Left)
	lvwCustomers.Columns.Add("Phone", 250, HorizontalAlignment.Left)

	' Adding Invoice Columns
	lvwInvoices.Columns.Add("InvID", 100, HorizontalAlignment.Left)
	lvwInvoices.Columns.Add("Created", 150, HorizontalAlignment.Left)
	lvwInvoices.Columns.Add("Status", 150, HorizontalAlignment.Left)
	lvwInvoices.Columns.Add("Sales Person", 250, HorizontalAlignment.Left)
	lvwInvoices.Columns.Add("Closed", 150, HorizontalAlignment.Left)

	Dim myCustomers As DataTable = On_OrderDataSet.Tables("Tbl_Customers")
	MsgBox("Customer Records = " & myCustomers.Rows.Count)

	Dim myInvoices As DataTable = On_OrderDataSet.Tables("Tbl_Invoices")
	MsgBox("Invoice Records = " & myInvoices.Rows.Count)

End Sub

Open in new window

LVL 83

Accepted Solution

CodeCruiser earned 250 total points
ID: 40204312
There should be a Fill call on the On_OrderDataSet somewhere. Do a search within the form and within the solution to find where that is. There needs to be a similar fill call for the other datatables.
LVL 14

Assisted Solution

quizwedge earned 250 total points
ID: 40205414
I'm referencing a previous question of yours that seems to be connected and may help us out:

It looks like you're not actually filling the tables using the fill command, but rather somehow through the Add -> Table Adapter wizard.

Check out You'll need to either add the additional queries to the Add -> Table Adapter wizard or you'll need to fill the dataset by doing something such as On_OrderDataSet.Fill(ds) where ds is your dataset.

Author Closing Comment

ID: 40206242
I found Me.Tbl_CustomersTableAdapter.Fill(Me.On_OrderDataSet.Tbl_Customers) hidden in the code.  Added additional ones ofr all other data tables and now it works great.  Thanks for helping me fix & understand the problem.

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question