I am using code that calculates the average of exams where the module code is CSC3047 as shown below:
avgObject = gradeTable.Compute("avg(exam)", "module_ID = CSC3047")
However i would like to calculate the average exam result where the module ID equals the selected value from a radio button which has a list of the modules.
Something like this:
avgObject = gradeTable.Compute("avg(exam)", "module_ID = radioList.selectedValue")
I know this is wrong but i have no idea how to accomplish this.
Dim condition As String = "module_ID=" + radioList.SelectedItem.Value.ToString()
avgObject = gradeTable.Compute("avg(exam)", condition)
Hope this will help you
Related
I am trying to pass a vba string variable to an IN clause of a SQL statement in the query builder view.
the string is created by the following function:
Public Function GetBackEnd()
If Len(GetBackEnd) = 0 Then GetBackEnd = BackEnd
End Function
backend itself is derived from a dropdown box in userform, there are two entries in a table with two different addresses, one each for the live and developement DB's. The dropdown box sets the "environment" variable upon selection.
Property Get BackEnd() As String
Select Case Environment
Case Is = "Development"
BackEnd = DLookup("VariableValue", "Globals", "Variable= 'TestEnvironment'")
Case Else
BackEnd = DLookup("VariableValue", "Globals", "Variable= 'Backend'")
End Select
End Property
I have tried a couple of variations on the following but get an error each time.
SELECT *
FROM TableName IN 'GetBackEnd()';
I imagine its something simple but after staring at this for so long Ijust can't see it.
thank you.
Generally, you can do what you want - use a function to provide parameter strings.
Public Function GetName() As String
GetName = "foo"
End Function
SELECT * FROM bar WHERE floo = GetName()
But in some parts / cases, you can't use variables. Both IN clauses are among them.
These won't work:
GetInList = "'x', 'y', 'z'"
SELECT * FROM bar WHERE floo IN (GetInList())
and your use-case is not possible either:
GetDbPath = "C:\path\myDb.accdb"
SELECT * FROM bar IN GetDbPath()
You will have to construct the whole SQL on the fly:
Db.QueryDefs("myQuery").SQL = "SELECT * FROM TableName IN '" & GetBackEnd() & "'"
Missing WHERE clause in SQL query? Let's say
SELECT *
FROM TableName
WHERE Name = GetBackEnd;
I have a pulldown text field with 15 options - Package 1, Package 2, through to Package 15.
Once a user selects a pulldown, the on change procedure is such that it populates the the fields in the form with the cooresponding data pulled in the select statement as the source of the pull down.
It works great until the user selects Package 10 or greater. the result is blank fields. Not exactly sure why and how to fix this.
Private Sub ColourPackage_Change()
Me.Brick.Value = Me.ColourPackage.Column(1)
Me.Stone.Value = Me.ColourPackage.Column(2)
Me.Shingles.Value = Me.ColourPackage.Column(3)
Me.Windows.Value = Me.ColourPackage.Column(4)
Me.GarageDoors.Value = Me.ColourPackage.Column(5)
Me.BoardBatton.Value = Me.ColourPackage.Column(6)
Me.Alluminum.Value = Me.ColourPackage.Column(7)
Me.Stucco.Value = Me.ColourPackage.Column(8)
Me.Shakes.Value = Me.ColourPackage.Column(9)
Me.Railing.Value = Me.ColourPackage.Column(10)
End Sub
Any help is greatly appreciated.
Use the AfterUpdate event:
Private Sub ColourPackage_AfterUpdate()
I need to migrate a CR report to RS.
I have two Methods, that are basically two queries, one is called "Products" the other one is called "Volume".
Both these datasets have a field called ID.
The idea is to count ProductsID = VolumeID. Can I use a lookup as an expression inside RS that counts when lookup is not equal to Nothing? Or I have to do a code to do that?
EDIT:
Let me add more information.
Crystal Report is managing these in the Data Layer of the web app like this:
DataRow drVol = vols.Rows.Find(new Object[] { id, idEzd });
if (drVol != null)
{
if (drVol["Volume"] != System.DBNull.Value)
cRow.Volume = (isNormalReport ? Convert.ToDecimal(drVol["Volume"]) : Convert.ToDecimal(drVol["Volume"]));
else
cRow.Volume = 0;
dset.Compradores.Rows.Add(cRow);
}
So in this case I verified that RS is giving me an X amount of rows while CR is giving me another amount of rows.
The Idea is to duplicate this on an expression or VB code inside RS.
As you can see, we have to filter the drVol != null, RS is bringing all the rows.
I know a Lookup function can be used in this case as:
Lookup(Fields!id.Value & Fields!idEzd.Value, Fields!id.Value & Fields!idEzd.Value,Fields!Givemethisfield.Value,"Dataset")
But can I use this Lookup expression inside a code to count?
The counter should be something like this (Then I should add the lookup or an if that equals that vlookup, can the code see the two datasets?):
Dim count=0 as integer
Public Function Counter() as Integer
count = count + 1
return count
End Function
Public Function GetCounter () as integer
return count
End Function
Then create a Calculated Field for example "Counter" with the expression
=Code.Counter()
And then make the sum of that calculated field:
=Sum(Fields!Counter.Value)
But is not working, not even the counter, is giving me 0.
Sorry if I made a mistake in the Visual Basic code, I don't program in Visual.
EDIT2:
I saw some workaround on MSDN, something like:
Lookup(Fields!id.Value & Fields!idEzd.Value, Fields!id.Value & Fields!idEzd.Value,Fields!Givemethisfield.Value,"Dataset").Lenght
It makes sense as a lookup is an Array.
The problem is, either if I choose one scope or the other, I still have the problem that some fields can't be seen for example if the fields id and idezd are on Dataset1 and Givemethisfield is on Dataset2, it will either not see the id,idEzd or Givemethisfield.
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
I am not sure what I am supposed to write in the code behind for my vb.net project. I have a repeater that filters a gridview. When trying to declare the scalar variable #CompanyID, I get the error I mentioned in the title of this post. Can someone help me? I have tried to look for the answer on many forums, but I can't find the right answer.
dsLetters.SelectCommand = "SELECT DISTINCT LEFT(ProductName, 1) AS [Letter]
FROM Product, CompanyLink, Company
WHERE Product.ProductID = CompanyLink.ProductID
AND CompanyLink.CompanyID = Company.CompanyID
AND Company.CompanyID = #CompanyID"
'declaring scalar variable #CompanyID
dsLetters.SelectParameters.Clear()
Dim cp As ControlParameter = New ControlParameter
cp.ControlID = "rptLetters"
cp.DefaultValue = "-1"
cp.Name = "CompanyID"
cp.PropertyName = "SelectedValue"
cp.Type = TypeCode.Decimal
dsLetters.SelectParameters.Add(cp)
I think the issue is that repeaters don't have the concept of a selected value; all they do is show what you have selected. What you may need to do is mimic the repeater values in a hidden dropdownlist and add client-side code to choose the appropriate value in the dropdownlist, then bind your ControlParameter to this property.