when quering customers from QBO i get duplicate customers - quickbooks-online

I seem to keep getting duplicates back when I query quickbooks online via the customer query. below is my code and I am wondering why i get the same customer back multiple times. I am using the paging feature to avoid timeouts.
Dim tCust As New List(Of Intuit.Ipp.Data.Qbo.Customer)
Dim qcust As New CustomerQuery
qcust.IncludeJobs = False
qcust.LastUpdatedTime = FromDate
qcust.PageNumber = 1
qcust.ResultsPerPage = 10
Dim customers As IEnumerable(Of Intuit.Ipp.Data.Qbo.Customer) = qcust.ExecuteQuery(Of Customer)(GetServiceContext)
While customers.Count > 0
tCust.AddRange(customers)
customers = qcust.ExecuteQuery(Of Customer)(GetServiceContext)
qcust.PageNumber += 1
End While

You are not incrementing the page number in the correct place, so you are executing two requests for PageNum=1 and ResultsPerPage=10.
The page number should be incremented in the loop as follows:
Dim tCust As New List(Of Intuit.Ipp.Data.Qbo.Customer)()
Dim qcust As New CustomerQuery()
qcust.IncludeJobs = False
qcust.LastUpdatedTime = New DateTime(2013, 1, 1)
qcust.PageNumber = 1
qcust.ResultsPerPage = 10
Dim customers As IEnumerable(Of Intuit.Ipp.Data.Qbo.Customer) = qcust.ExecuteQuery(Of Customer)(context)
While customers.Any()
tCust.AddRange(customers)
If customers.Count() < qcust.ResultsPerPage Then Exit While
qcust.PageNumber += 1
customers = qcust.ExecuteQuery(Of Customer)(context)
End While

Related

Duplicate X Axis for Graph (VB.net)

I am having some issues with my VB.net database, I am trying to present a chart which shows a composition of customers who are members or not from a graph. The graph works, however; there are duplicates (as there are 8 bars instead of 2 bars):
For my database, I've used lists rather than conventional methods such as SQL. However, I'm uncertain if I've made a mistake or I'm missing something, here's the code:
Dim a As Integer
Dim b As Integer
Dim status As String
Dim countList As New List(Of Integer)
Dim statusList As New List(Of String)
Dim yesList As New List(Of String)
Dim count As Integer = 0
For a = 0 To memberList.Count - 1
status = memberList.Item(a).memberStatus
count = 0
For b = 0 To memberList.Count - 1
If status = memberList.Item(b).memberStatus Then
count = count + 1
End If
Next
statusList.Add(memberList.Item(a).memberStatus)
countList.Add(count)
Next
For i = 0 To countList.Count - 1
Debug.Print(memberList(i).memberStatus & countList(i).ToString)
Next
Chart_MemMostPopularTown.ChartAreas("ChartArea1").AxisX.MinorTickMark.Enabled = True
Chart_MemMostPopularTown.ChartAreas("ChartArea1").AxisX.Interval = 1
Chart_MemMostPopularTown.ChartAreas("ChartArea1").AxisX.IsLabelAutoFit = True
Chart_MemMostPopularTown.ChartAreas("ChartArea1").AxisX.LabelAutoFitStyle = DataVisualization.Charting.LabelAutoFitStyles.DecreaseFont
Chart_MemMostPopularTown.Series(0).Points.DataBindXY(statusList, countList)
If there is anything I've missed out, or if I've been too vague; please do let me know. I'm new to this site BTW so apologise for mistakes or lack of clarity.
Kind Regards

Reading data from LINQ query

I am new to LINQ query and writing a SSIS script task to read data from two data tables.
I have created the following query, where I want to output to be sent by an email as a table. The body of the email will be the output.
I am able to see the result. But dont know how to use this data (New to linq).
Here is my code:-
Dim Filename As String
Dim Filepath As String
Dim i As Integer
Filename = "TM_xxx_DAILY_*" + Dts.Variables("User::VLoaddt").Value.ToString + "_*.txt"
Filepath = Dts.Variables("User::vSrcFolder").Value.ToString
Dim di As DirectoryInfo = New DirectoryInfo(Filepath)
Dim fi As FileInfo() = di.GetFiles(Filename)
Dim DestTab As DataTable
DestTab = New DataTable("DestinationTable")
Dim column As DataColumn = New DataColumn("Dest")
column.DataType = System.Type.GetType("System.String")
DestTab.Columns.Add(column)
DestTab.Rows.Add("TM_xxx_ONLINE")
DestTab.Rows.Add("TM_xxx_RETAIL")
DestTab.Rows.Add("TM_xxx_TELESALES")
DestTab.Rows.Add("TM_xxx_DAILY_DEVICE")
Dim SrcTab As DataTable
SrcTab = New DataTable("SourceTable")
Dim column1 As DataColumn = New DataColumn("Source")
column1.DataType = System.Type.GetType("System.String")
Dim column2 As DataColumn = New DataColumn("FileExists")
column2.DataType = System.Type.GetType("System.String")
SrcTab.Columns.Add(column1)
SrcTab.Columns.Add(column2)
For i = 0 To fi.Length - 1
SrcTab.Rows.Add(Left(fi.GetValue(i).ToString, Len(fi.GetValue(i).ToString) - 20), "Exists")
Next
Dim query =
From a In DestTab
Group Join b In SrcTab
On a.Field(Of String)("dest") Equals b.Field(Of String)("Source")
Into Group
Let b = Group.FirstOrDefault
Select dest = a.Field(Of String)("dest"), FileExists = If(b Is Nothing, "Missing", b.Field(Of String)("FileExists"))
The biggest challenge and I am not able to understand how to use the variable "query" in "Dim query". While examples in the net and able to use it as a datarow, copytodatatable and other. I can only see tostring,equals and things like that.
My objective is to read files in a folder join it with "Destinationtable" and find the missing ones.
The codes written below are the one right after the select statement
Error Screenshots
I think you should use
For each line in query.ToList()
Dim drRow as DataRow
drRow = MT.NewRow
drRow("Filename") = line.Item(0)
MT.Rows.Add(drRow)
Next
Instead of
For each line in query
MT.Rows.Add(query)
Next

Reading Data from Access database and adding to a combox is very slow

So Ive been trying to read from a large access database and the table iam trying to read from contains nearly 20000 entries, all of which are needed in the combox. With some testing I have figured out that the program slows down the longer it runs. The first 5000 are added almost instantaneously, but the next 5000 increment increase exponentially. Over all it would take about 5 minutes to load the entire thing. Am i missing something that will make it more efficient? Ive attached the function iam using below. It is in Vb.net
Private Sub chkBoxPurchasedPart_CheckedChanged(sender As Object, e As EventArgs) Handles chkBoxPurchasedPart.CheckedChanged
If (chkBoxPurchasedPart.Checked) Then
chkBoxRawMaterial.Checked = False
chkBoxSkipMaterialSelection.Checked = False
MaterialButton.Enabled = True
comboxMaterial.Sorted = True
comboxMaterialHdn.Text = "AS SUPPLIED"
comboxMaterialHdn.Enabled = False
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim oConnect, oQuery As String
oConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Y:\eng\ENG_ACCESS_DATABASES\VisibPartAttributes.mdb"
oQuery = "SELECT * FROM VISIB_PARTMASTER_LOCAL WHERE PRODUCT_LINE LIKE '%PUR%' OR PRODUCT_LINE LIKE '%NOSTD%' AND PARTDESCR NOT LIKE '%OBSOLETE%'"
Try
cn.Open()
Catch ex As Exception
Finally
cn = New OleDbConnection(oConnect)
cn.Open()
End Try
cmd = New OleDbCommand(oQuery, cn)
dr = cmd.ExecuteReader
comboxMaterial.Items.Add("- - OTHER - -")
While dr.Read()
comboxMaterial.Items.Add(dr(0))
End While
dr.Close()
cn.Close()
Try
Dim s As Session = Session.GetSession()
Dim dispPart As Part = s.Parts.Display()
Dim c As NXOpen.Assemblies.Component = dispPart.ComponentAssembly.RootComponent
Dim children As NXOpen.Assemblies.Component() = c.GetChildren()
Dim childMaterial As String = Nothing
For Each child As NXOpen.Assemblies.Component In children
childMaterial = child.GetStringAttribute("STACKTECK_PARTN")
If (childMaterial.Length > 5 Or child.Name.StartsWith("PUR")) Then
comboxMaterial.Text = childMaterial
End If
Next
Catch ex As Exception
End Try
ElseIf (chkBoxPurchasedPart.Checked = False) Then
comboxMaterialHdn.Text = ""
comboxMaterialHdn.Enabled = True
txtBoxDiameter.Enabled = True
txtBoxRoundLength.Enabled = True
txtBoxInnerDiameter.Enabled = True
txtBoxLength.Enabled = True
txtBoxWidth.Enabled = True
txtBoxThickness.Enabled = True
MaterialButton.Enabled = False
txtBoxVisMaterial.Text = ""
txtBoxVisMaterialDescription.Text = ""
txtBoxEachQuantity.Text = ""
txtBoxTotalQuantity.Text = ""
txtBoxUnitOfMeasure.Text = ""
comboxMaterial.Sorted = False
comboxMaterial.Items.Clear()
comboxMaterial.Text = ""
End If
End Sub
For anyone in the future having a similar issue, the combobox wasnt the problem, the previous designer had the AutoCompleteMode set to suggest and append which slowed the entire process down. Disable it and your program should speed up.
I would only load the combo-box records after the first 3 or 4 characters have been entered. This should drastically reduce the number of records being returned, and a still allow the autocomplete to work.
This thread has code to assist you : get 65K records only listed in combo box from a table of 155K records

Need Help properly displaying an array in a listbox

Public Class Form1
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim Teams() As String = IO.File.ReadAllLines("SBWinners.txt")
Dim Team As String
Dim SteelersWins As Integer = 0
Dim RaidersWins As Integer = 0
Dim PackersWins As Integer = 0
Dim CowboysWins As Integer = 0
Dim GiantsWins As Integer = 0
Dim RamsWins As Integer = 0
Dim RavensWins As Integer = 0
Dim SaintsWins As Integer = 0
Dim FortyNinersWins As Integer = 0
Dim RedskinsWins As Integer = 0
Dim BroncosWins As Integer = 0
Dim PatriotsWins As Integer = 0
Dim ColtsWins As Integer = 0
Dim DolphinsWins As Integer = 0
Dim BearsWins As Integer = 0
Dim JetsWins As Integer = 0
Dim ChiefsWins As Integer = 0
Dim BuccWins As Integer = 0
For Each team In Teams
If team = "Steelers" Then
SteelersWins += 1
End If
If team = "Raiders" Then
RaidersWins += 1
End If
If team = "Packers" Then
PackersWins += 1
End If
If team = "Cowboys" Then
CowboysWins += 1
End If
If Team = "Giants" Then
GiantsWins += 1
End If
If team = "Rams" Then
RamsWins += 1
End If
If team = "Ravens" Then
RavensWins += 1
End If
If team = "Saints" Then
SaintsWins += 1
End If
If team = "Forty-Niners" Then
FortyNinersWins += 1
End If
If team = "Redskins" Then
RedskinsWins += 1
End If
If team = "Broncos" Then
BroncosWins += 1
End If
If team = "Patriots" Then
PatriotsWins += 1
End If
If team = "Colts" Then
ColtsWins += 1
End If
If team = "Dolphins" Then
DolphinsWins += 1
End If
If team = "Bears" Then
BearsWins += 1
End If
If team = "Jets" Then
JetsWins += 1
End If
If Team = "Chiefs" Then
ChiefsWins += 1
End If
If team = "Buccaneers" Then
BuccWins += 1
End If
Next
Dim Wins() As Integer = {SteelersWins, RaidersWins, PackersWins, CowboysWins, GiantsWins, RamsWins, RavensWins, SaintsWins, FortyNinersWins, RedskinsWins,
BroncosWins, PatriotsWins, ColtsWins, DolphinsWins, BearsWins, JetsWins, ChiefsWins, BuccWins}
For Each win In Wins
Array.Sort(Wins)
Array.Reverse(Wins)
lstOutput.Items.Add(win)
Next
End Sub
End Class
What I have right now is code that reads a text file with the names of Superbowl winners, and counts the number of wins by the number of times the team name appears. These wins are then put into an array and sorted in descending order and displayed in a listbox. This all works fine.
My problem is that I need to display the corresponding team name with their number of wins on the same line in the listbox. So, instead of being:
6
5
5
4
4
It needs to be:
6 Steelers
5 49ers
5 Cowboys
4 Giants
4 Packers
And so on.
There are a couple of issues with your code, not the least of which is you are using hard coded names and variables to collect your team information. This is severely limiting if new names are added or names change.
As Plutonix mentioned in the comments you need to use a class to properly identify and collate your information. I also strongly suggest you use a List(of T) collection to contain your data.
The following code does what you desire.
Private Class cls_Team_wins
Public Team_Name As String
Public Wins As Integer
Public Sub New(Name As String)
Team_Name = Name
Wins = 1
End Sub
Public Overrides Function ToString() As String
Return Strings.Right(" " & Wins, 2) & " - " & Team_Name
End Function
End Class
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim Games = New List(Of cls_Team_wins)
Dim Teams() As String = IO.File.ReadAllLines("SBWinners.txt")
For Each Team As String In Teams
If Team <> "" Then
Dim Team_Win As cls_Team_wins = Games.Find(Function(x) x.Team_Name = Team)
If Team_Win Is Nothing Then
Games.Add(New cls_Team_wins(Team))
Else
Team_Win.Wins += 1
End If
End If
Next
Games.Sort(Function(x, y) -x.Wins.CompareTo(y.Wins))
ListBox1.DataSource = Games
End Sub
The class included the team name and win counter. It over-rides the ToString method so the list box knows what to show as text. The New function requires you pass the team name and presets the win counter to one.
The For Loop checks for and ignores blank team names, this can be an issue reading text files, esp on the last line. Otherwise it will either add a new team to the list if it does not already exist, or it will increment the win counter if it does.
Once the list is built it is reverse sorted (Note the minus sign in the "Function" compare statement, that's a little trick that reverses the sort), and finally given to the listbox as a datasource.
Good luck to you :)

Query works in Sql but returns empty datatable

Edit
I'm so confused, now I changed this if statement:
If Data.Rows.Count > 0 Then
'Do all Voucher things in here
else
txtVoucher.text = "Sorry, Invalid Voucher"
end if
To display the query from the voucher checking function by outputting it as one of Voucher's string properties, like this:
else txtvoucher.text = Voucher.voucherName end if
And everything works fine! If I change it back to an error message... the datatable returns no rows. I haven't changed anything else about the code, just what goes to the textbox if the row count is 0. Shouldn't the row count be the same regardless of what I send to the textbox afterward?
End Edit
I am making a basic Online Voucher function for a webpage and am having issues with the voucher checking query.
I have this query, which checks the string entered into a textbox against the SQL table for a match.
Public Shared Function CheckForVoucher(ByVal strVoucherName As String) As DataTable
Dim connect As New SqlConnection
Dim Data As New DataTable 'Connection works, finds number of Vouchers in DB that match either code or ID. ID to be used for randomly generated vouchers.
connect.ConnectionString = "SERVER = SERVER-SQL01; Trusted_Connection=yes; DATABASE=PCSQL"
connect.Open()
Dim query As String
Dim search As String
search = strVoucherName
If search.Length >= 20 Then
query = "SELECT * from PCSQL.dbo.VOUCHER_DETAILS WHERE vID='" + search + "' "
Else
query = "SELECT * from PCSQL.dbo.VOUCHER_DETAILS WHERE voucherName='" + search + "' "
End If
Dim command = New SqlDataAdapter(query, connect)
command.Fill(Data)
connect.Close()
Return Data
End Function
The query works fine in SQL Manager, I can replace the keyword search with any of the voucher names I have in the list and it returns the correct result, same goes if I replace the search keyword in vb.net and force the query to check for a specific voucher no matter what is entered in the textbox (e.g. TestVoucher2).
I currently have the page set to check for results as below.
Protected Sub lbVoucherCheck_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbVoucherCheck.Click
'Voucher checking code to go here
Dim Data As DataTable = Voucher.CheckForVoucher(txtVoucher.Text)
If Data.Rows.Count > 0 Then
Dim row As DataRow
row = Data.Rows(0)
'Set voucher properties in Voucher.vb using datarow result.
Voucher.VoucherID = row.Item("vID").ToString().Trim()
Voucher.VoucherName = row.Item("voucherName").ToString().Trim()
Voucher.ExpiryDate = row.Item("ExpiryDate")
Voucher.ValidUses = row.Item("ValidUses")
Voucher.CurrentUses = row.Item("CurrentUses")
Voucher.DiscountType = row.Item("DiscountType").ToString().Trim()
Voucher.AppliesTo = row.Item("AppliesTo").ToString().Trim()
Voucher.NumberOf = row.Item("NumberOf").ToString().Trim()
Voucher.Amount = row.Item("Amount")
Voucher.noOfItems = row.Item("NoOfItems")
Voucher.Category = row.Item("Category").ToString().Trim()
Voucher.FreebieID = row.Item("FreebieID").ToString().Trim()
Voucher.DiscountAmount = row.Item("DiscountAmount")
'lbVoucherCheck.Text = Data.ToString()
'Step one: Check for Expiry Date
Dim count As Int32
count = 0
Dim expiry As DateTime = Voucher.ExpiryDate
Dim today As DateTime = Date.Today()
count = ((expiry - today).Days)
If count <= -1 Then
txtVoucher.Text = "Voucher expired"
Else
txtVoucher.Text = "Expires in " + count.ToString() + " days."
End If
Else
txtVoucher.Text = Data.rows.count
End If
End Sub
When I run the query based off txtVoucher.Text input it returns "0", indicating that it hasn't found anything. But If I rig the query with a voucher name it returns the correct expiry result.
I have a strong feeling that it's not getting the right information from txtVoucher.text to my Voucher.CheckForVoucher(txtVoucher.text) function.

Resources