visual basic find database total - sql

I'm working on creating a visual basic program that can find the sum total of a column from a database file and display it in a label control, and have been stuck for a while. I was hoping that someone could help me out a little.
I've tried a few different ways to accomplish it and they each keep throwing out the same error.
Dim SumQuery = From popualtion In PopulationDBDataSet.City
Aggregate order In PopulationDBDataSet.City
Into Sum(PopulationDBDataSet.City.PopulationColumn)
lblTotalPop.Text = SumQuery.ToString
and
Dim SumQuery = Aggregate Populaton In PopulationDBDataSet.City
Into Sumorders = Sum(PopulationDBDataSet.City.PopulationColumn)
lblAvgPop.Text = SumQuery.ToString
Both attempts produce the error "method sum not accessible in this context". Sorry for this post being a bit long but I'm out of ideas on this.

Your usage should include the variable used in Aggregate function:
Try this:
Dim SumQuery = From popualtion In PopulationDBDataSet.City
Aggregate order In PopulationDBDataSet.City
Into Sum(order.PopulationColumn)

Related

EXISTS function returns first values only

Can someone please help me out understand what am I doing wrong?
I have the following structure of my CUBE:
And I`m creating the following calculated member in MDX in Visual Studio:
CREATE MEMBER CURRENTCUBE.[Measures].[Current_State]
AS EXISTS([DWH Dim Work Item Current].[State].[State].Members,[DWH Dim Work Item Current].[Title].Currentmember).Item(0).Name,
VISIBLE = 1;
But for some reason I get only the first value (i.e. "Active") for every row in Excel:
Can someone please tell me what I`m doing wrong and how I should fix it?
Thank you in advance!
Does EXISTING work any better?
CREATE MEMBER CURRENTCUBE.[Measures].[Current_State]
AS EXISTING([DWH Dim Work Item Current].[State].[State].MEMBERS).ITEM(0).NAME,
VISIBLE = 1;

Creating Query on the fly - EF Linq

I'm trying to convert a functional hard code query to a dinamic query. With my knowledge this is a impossible task.
Can anybody help me? This is the hard code query. This works fine:
Dim ret0 = qry.AsQueryable.Select(Function(f) New With { f.id, f.bint1, f.scampo1})
Where qry is a "return content table" comes from another query.
I've try:
Dim ret99 = qry.AsQueryable().Select(Function(f) ("new (key.id, key.bint1, key.scampo1)"))
and other variations but not is working.
If I do something like that:
Dim ret1 = qry.AsQueryable().Select("scampo1")
this works fine. But if I try more than one column only the very first one is returned.
Hope somebody could help me on that.

Binding VB.net DataRepeater to dataview items at runtime with aggregation using linq

Hoping someone can help me out with what is probably a dumb question.
I'm trying to use a datarepeater to display data generated via LINQ from a datatable
I've managed to do this fine with a filtered existing datasource using:
Me.Tbl_52TableAdapter.Fill(Me.CBRDataSet.tbl_52)
Dim query =
From dlist In CBRDataSet.tbl_52.AsEnumerable
Where (dlist.Field(Of String)("TL") = "CTS 06")
Select dlist
query.CopyToDataTable().AsDataView()
DataRepeater1.DataSource = query
The problem being that I need to aggregate a field in the dataset into a count.
If I replace the query with:
Dim query =
From CountAgent In CBRDataSet.tbl_52.AsEnumerable
Group CountAgent By PBX = CountAgent.Field(Of String)("TL") Into Count()
Select Count
It then states that:
'CopyToDataTable' is not a member of 'System.Collections.Generic.IEnumerable(Of Integer)'
I've tried to get around it by changing the declaration to:
Dim query As IEnumerable(Of DataRow) =
Which compiles, but I have no idea if it works, and I cant check as I can't find a way to bind a label to the produced count col of the dataview.
If anyone can tell me what I'm doing wrong i'd be most appreciative.
Coming back to my own question, in case it helps anyone else: MSDN had the answer -
You need to overload copyToDataTable as described in
"How to: Implement CopyToDataTable Where the Generic Type T Is Not a DataRow"
on:
http://msdn.microsoft.com/en-us/library/bb669096.aspx

Reading and changing fields in SAP with RFC via VB .NET

I'm currently trying to figure out the basics of remote function calls via vb .NET. I feel pretty helpless however, because their just isn't any useful documentation for the most simple of tasks.
What I'm trying to do atm is starting the transaction CO13, write the confirmation number in the appropriate field and cancel the order. Even this simple tasks turned out to be a pain in the ass. I'm still not sure how to access and modify the contents of a specific field. There are some examples with tables for excel in the net, but hat's about it. What I have so far is this (login is working and in another function):
Public Function stornieren() As Boolean
Dim ordernr As String
Dim confirmationnr
Dim confirmation As Object
Dim R3 As Object
Dim CO13 As Object
Dim result
R3 = CreateObject("SAP.Functions")
ordernr = TextBox3.Text
confirmationnr = TextBox4.Text
CO13 = R3.Add("RFC_CALL_TRANSACTION_USING")
CO13.exports("TCODE") = "CO13"
CO13.exports("MODE") = "S"
confirmation = CO13.exports("RUECK")
confirmation.value = confirmationnr
result = CO13.call
End Function
RUECK is the Field Name. I want to write the value of "confirmationnr" into the field RUECK. "confirmation.value = confirmationnr" throws the error message "the object variable could not be determined" and "NullReferenceException" was not handled. Sounds to me like the object is empty.
Thanks in advance.
EDIT: Now trying via BAPIs and particularly BAPI_PRODORDCONF_CANCEL. I have no idea about the syntax though. Any help would be appreciated.

I need to round a value up in vb.net

I,m developing a debt calculation program 'my problem is when i have to calculate the months to pay back the debt it comes to 28.04 and i have to get it to 29 can some one pls help me out.
Thank you in advance
my code looks like this:
Dim b, SubMtP As Integer
Dim outsUm, si
outsUm = TextBox1.Text
SubMtP = Format(Val(TextBox1.Text) / Val(TextBox2.Text), "0.00")
Math.Round(SubMtP + 1)
TextBox5.Text = Format(Val(TextBox4.Text) / 12, "0.00")
For i As Integer = 1 To SubMtP
Use Math.Ceiling.
As Pavel said in the comment, you need to assign the result, and you should use Ceiling:
Dim result As Double = Math.Ceiling(SubMtP)
You are also strongly encouraged to switch Option Strict On everywhere in your code to enable strict, static type checking. This will result in a few compile errors in your above code that will need to be cleaned up. This is good because these code fragments are potential errors in your code and make it hard to maintain and to understand.
The line
Math.Round(SubMtP + 1)
does not do anything (has no side effects) since you aren't assinging or otherwise using the result.
If you are trying to get from 28.04 to 29 then you probably want Math.Ceiling. It's hard to tell what you are trying to do, but you probably want
SubMtP = Math.Ceiling(SubMtP);