QBSDK invoice query - vb.net

I am using vb.net in visual studio to query my invoices.
i get a list of invoice of interest, and as i iterate through the list, i see the for each invoice i have, the invoice.ORInvoiceLineRetList is nothing.
here is a snippet of code, although i think i am doing everything right?
resp = SessMgr.DoRequests(msgReq)
resplist = resp.ResponseList
curResp = resplist.GetAt(0)
If curResp.StatusCode = 0 Then
Dim invoiceList As IInvoiceRetList = curResp.Detail
Dim curInvoice As IInvoiceRet
Dim i As Integer
For i = 0 To invoiceList.Count - 1
curInvoice = invoiceList.GetAt(i)
if i breakpoint right after the last line, i see curInvoice, and its data (e.g. refnumber), but i need to get to the line items.
can someone help?
Thanks,
Jerry

If your IInvoiceQuery is called invoiceQuery, add this (just replace invoice query with your IInvoiceQuery objects name if it's called something else)
invoiceQuery.IncludeLineItems.SetValue(True)
before this
resp = SessMgr.DoRequests(msgReq)
and that should fix your problem

Related

.Select return wrong length

I'm trying to check if the field data of my DataTable records is set to '0' or '1'. All my local record is saved into local_ds DataTable. Now, the record that I want check is this: 21a956af-f304-4c72-97cf-1ef08e8719fc
for a better vision I paste here the content of my table (that is also the content of my DataTable local_ds):
How you can see the record that I want check have the field data set to 0. Now I perform the research through this code:
Dim local_data = local_ds.Tables(0).Select(String.Format("GUID = '{0}'", "21a956af-f304-4c72-97cf-1ef08e8719fc"), String.Format("data", 1))
The code above use LINQ to take the result, anyway, I pass the GUID field to search and the field data as 1. This code should be return local_data.length equal to 0 but, instead, return 1 and this is wrong, 'cause I want to check only if the field data is 0 or 1. In this example the result should be local_data.length = 0 'cause in the LINQ query I specified clearly that I want find the record with GUID = x and data = 1.
I already know that this record exists in the database, the local_data variable must help me to recognize which type of valorization the data field have.
So, what I did wrong?
No, in the code above, you are not using LINQ.
DataTable.Select is a method available starting from the 1.1 version of NET Framework and exists in four possible overloads.
The one you are using is the one that takes, as first parameter, the WHERE condition and, as second parameter, the SORT order. So you are not really passing a condition WHERE .... AND Data = 1 but the Data=1 it is interpreted as a sort order of some kind.
The correct string for the WHERE parameter should be
Dim where as String = String.Format("GUID = '{0}' AND Data = {1}", _
"21a956af-f304-4c72-97cf-1ef08e8719fc", 1)
Dim local_data = local_ds.Tables(0).Select(where)

select count on list using linq on specific value vb.net

I am having an issue getting the results I am looking for. What I need to do is essentially:
Select count(invoicenbr) from invoicelist where invoicenbr = 'invoice'
but when I try it in linq I am not getting the correct results.
When I try to execute the linq query below, it gives me the count for the entire list, and not for the where invoicenbr = 'invoice'...
Here is my linq query that is returning the count for the entire invoiceList:
Dim test = (From invoices In invoicelist _
Where e.Row.Cells("invoicenbr").Value = invoice).count()
You have a naming issue in your code, i assume that it's responsible for your problem.
The variable in your query is invoices but later you use invoice to compare it with the cell value, so you have a different variable in scope with name invoice.
This should work:
Dim invoicenbr As String = e.Row.Cells("invoicenbr").Value
Dim duplicates = From invoice In invoicelist
Where invoice = invoicenbr
Dim duplicateCount As Int32 = duplicates.Count()

DataTable.Select.Where VB.Net - Delete rows

I'm currently pulling information using a query that I'm not allowed to tamper with:
Dim dt As DataTable = BLL.GetData(variable).Tables(0)
Immediately afterwards, I'm removing any records where a field begins with a specific value:
For Each dr As DataRow In dt.Rows
If dr.Item(2).ToString().StartsWith("value") Then
dr.Delete()
End If
Next
What I'd really like to do is something like:
dt.Select.Where(field1 => field1.StartsWith("value")).Delete()
I know that is not the syntax of it and I'm probably very off from what it would be like. The For Each works fine, I'm just trying to "simplify" it. Any idea? Any and all help is appreciated.
Actually, your initial code is probably the cleanest and most straight forward.
To delete items using LINQ, you first need to read them into a separate collection, then loop through that collection and call Delete on each record. If you'd rather go that route, you could try:
Dim records = dt.Rows.Where(Function(r) r.StartsWith("value")).ToList()
For Each r In records
r.Delete()
Next
The answer I think you are looking for is below from Microsoft. https://msdn.microsoft.com/en-us/library/det4aw50(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
Dim table As DataTable = DataSet1.Tables("Orders")
' Presuming the DataTable has a column named Date.
Dim expression As String
expression = "Date > #1/1/00#"
Dim foundRows() As DataRow
' Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression)
Dim i As Integer
' Print column 0 of each returned row.
For i = 0 to foundRows.GetUpperBound(0)
Console.WriteLine(foundRows(i)(0))
Next i

VB .net - stored procedure - line number count

I'm back again as I'm waiting for the coffee to kick in and have another question that seems to be not causing my brain cells to fire correctly.
I've set the following code to determine the line numbers of all rows returned from the procedure loop.
linenum = 0
Do While (rsData.Read())
linenum = linenum + 1
loop
Now I'm trying to code a button that will move users to different sections depending on the linenumber returned.
So if there's only one linenum with a value of 1, they get a button to 'Apply'.
If the total linenum values are greater than 1, they get a button to 'select apply date'.
Now again I'm having a brain fart and can't think of the logic if theres a linenum of 1+ how to determine the button should be displayed. It needs to include the value of 1 as well as there are more than one linenums so the button should display the 'select apply button'.
Any ideas?
Thanks!
I think you'll have better luck populating a DataTable and using the row indexes, or returning the row number from the stored procedure.
SELECT ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS Row, FirstName, LastName, ROUND(SalesYTD,2,1) AS YTD
FROM Sales.vSalesPerson
WHERE TerritoryName IS NOT NULL AND SalesYTD <> 0
It looks like you're using a SqlDataReader currently, so it shouldn't be too difficult to adjust so it returns a DataTable instead:
DataTable table = new DataTable();
using (SqlDataAdapter adap = new SqlDataAdapter(cmd))
{
adap.Fill(table);
}
Not clear what you're trying to accomplish, but to directly answer your question:
if linenum = 0 then
mybutton.visible = false
else if linenum = 1 then
mybutton.visible = true
mybutton.text = "Apply"
else
mybutton.visible=true
mybutton.text = "Apply select"
end if
But I would think that if linenum > 1, someplace you also have to giv the user the list of things to select from, and a way to select one of them. Like build a dropdown box or something.

Looping with List(of objects) in vb.net

I have a procedure in VB.net using VS.net 2008 which will get the list of Orders and build a XML file with the list of Orders as shown in the code below:
As the number of Orders is getting huge, I want to build the XML file for every 500 Orders
Dim Orders as List(of Orders)=DAL.GetAllOrders()
Dim Order as new Orders
Public xmlstring As New StringBuilder
If Not Orders Is Nothing Then
xmlstring.Append("<?xml version=""1.0"" encoding=""Windows-1252"" standalone=""yes""?>")
xmlstring.Append("<Orders>")
For Each Order In Orders
'Build the XML File
next
'access web service and pass the XML file
end if
Instead of building XML for all the records I want to create XML for each 500 records.
I tried the following code and it is throwing an error saying
Expression is of type Orders which is not a collection type.
Please help
Dim start As Integer
For i As Integer = start To Orders.Count Step 500
xmlstring.Append("<?xml version=""1.0"" encoding=""Windows-1252"" standalone=""yes""?>")
xmlstring.Append("<Orders>")
For Each Order In Orders(i)
'Build the XML File
next
next
Some issues to resolve:
Step 500 will SKIP 500 rows at a time. I.e., it will write Order #1, then order #501, then #1001, etc. You'll need to track your orders-per-count yourself.
Your use of variable names for Order/Orders vs. the class names is confusing, and is tripping you up.
XML should be built via the XML tools in .NET, not by string concat. You're going to build yourself into a brick wall quickly.
Loop construct:
Dim Orders as List(of Order) = DAL.GetAllOrders()
If Not Orders Is Nothing Then
Dim i As Integer = 1
For Each order As Order In Orders
If i=500 Then
' write XML footers, close the current file
' open the next file, write XML header
i = 1
Else
i += 1
End If
' write XML for this order
Next
' Write final XML footer and close current file
End If
it is throwing an error saying Expression is of type Orders which is not a collection type.
The variable "Orders" is a collection type (List(of Orders)), but Orders(i) is not, it is an "Orders" (whatever that is, you have not posted the definition) object.
So, you need to either implement IEnumerable in your Orders class or change this line:
For Each Order In Orders(i)
I would use something like this:
for i as integer = 0 to orders.count - 1
<create xml here and put into variable (append new XML as needed)>
if (i mod 500 = 0 andalso not i = 0) orelse i = orders.count - 1 then
<output XML here and clear XML variable>
end if
next i
How about something like this:
Dim OrdersList as List(of Orders)=DAL.GetAllOrders()
For i as int32 = 0 to OrdersList.Count() - 1
Dim o as Orders = OrdersList(i)
'Build your xml
If i mod 500 = 0 Then
'write out xml & reset your string builder
End If
Next
*Note I changed your Orders variable as the naming convention was a little confusing and might be causing name collisions.