Solved

Why does this DataTable have no data in it?

Posted on 2014-07-17
8
139 Views
Last Modified: 2014-07-19
Hello,

Using VS2013 to program a Windows Form application in VB.net.

Created DataSource which links to an Access mdb database:
Screenshot of VB.net 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
MsgBox(myCustomers.Rows.Count)

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
MsgBox(myInvoices.Rows.Count)

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!

Thanks,
Jason
TblInvoices.png
TblCustomers.png
0
Comment
Question by:SqueezeOJ
[X]
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
8 Comments
 

Author Comment

by:SqueezeOJ
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.
0
 
LVL 14

Expert Comment

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

Author Comment

by:SqueezeOJ
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!
0
Independent Software Vendors: 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

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

Author Comment

by:SqueezeOJ
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

0
 
LVL 83

Accepted Solution

by:
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.
0
 
LVL 14

Assisted Solution

by:quizwedge
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: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_28474839.html

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 http://msdn.microsoft.com/en-us/library/aa728893(v=vs.71).aspx 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.
0
 

Author Closing Comment

by:SqueezeOJ
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.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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