Solved

Why does this DataTable have no data in it?

Posted on 2014-07-17
8
129 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
  • 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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40204165
Can you show us code from your Form_Load event?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now