LINQ query update to accommodate changes - vb.net

I need help in combining below SQL to code
Dim queryPersons = Query.From("ADSAccountInADSGroup") _
.Where(Function(t) t.Column("UID_ADSAccount") = uidAdsAccount) _
.SelectAll()
I'm successfull only until UID_ADsAccount = '4f58406f-8823-4530-b763-d344fc9093ed')
I need to append below piece of code as well to Dim queryPersons
and uid_adsgroup not in(select uid_adsgroup from adsgroup where cn like 'Domain%'))
and (XMarkedForDeletion <> 2) and (XOrigin = 1)))

Related

Why Application.Worksheetfunction.Countifs doesn`t return value?

Dim SJtempARTIST, SJtempSTATION, SJtempADD, SJtempSPINS, targetCELL As Range
Dim stationARTIST, stationSTATION As String
Sheets("STATIONS").Select
For RARTSTAT = 2 To lrARTSTAT1
stationARTIST = Worksheets("STATIONS").Cells(1, cARTIST)
stationSTATION = Worksheets("STATIONS").Cells(RARTSTAT, 2)
Set SJtempARTIST = Worksheets("TEMPDB").Range("A1:A" & lrSJIMPORT2)
Set SJtempSTATION = Worksheets("TEMPDB").Range("C1:C" & lrSJIMPORT2)
Set SJtempADD = Worksheets("TEMPDB").Range("F1:F" & lrSJIMPORT2)
Set SJtempSPINS = Worksheets("TEMPDB").Range("E1:E" & lrSJIMPORT2)
Set targetCELL = Sheets("STATIONS").Cells(RARTSTAT, cARTIST)
checkRECORD = Application.WorksheetFunction.CountIfs(SJtempSTATION, _
stationSTATION, SJtempARTIST, stationARTIST)
checkADD = Application.WorksheetFunction.CountIfs(SJtempSTATION, _
stationSTATION, SJtempARTIST, stationARTIST, SJtempADD, 1)
checkSPINS = Application.WorksheetFunction.SumIfs(SJtempSPINS, _
SJtempSTATION, stationSTATION, SJtempARTIST, stationARTIST)
checkX = InStr(1, LCase(targetCELL), "x")
checkADD = InStr(1, LCase(targetCELL), "add")
Hello guys. Well here is one part of code. Variable checkADD returns value 0 while clearly it shouldn`t, as rest of variables returning values properly. Anyway, here is more info:
checkRECORD finds and count properly 1 record. checkADD should too as it is using same method with one criteria and range more (in that F1:F column values can be either 0 either 1, and I want to count 1`s).
Ive tried with SUMIFS to, but still doesnt count anything. Ive checked ranges, and checked criteria`s and everything is fine! Ive tried without variables (with full ranges) but without luck.
So question is... why COUNTIFS doesnt work here?
Thnx in advance
Sorry guys for taking your time, mistake was mine ofc....
checkADD = Application.WorksheetFunction.CountIfs(SJtempSTATION, _
stationSTATION, SJtempARTIST, stationARTIST, SJtempADD, 1)
checkSPINS = Application.WorksheetFunction.SumIfs(SJtempSPINS, _
SJtempSTATION, stationSTATION, SJtempARTIST, stationARTIST)
checkX = InStr(1, LCase(targetCELL), "x")
checkADD = InStr(1, LCase(targetCELL), "add")
I named checkADD variable two times. It is too late I guess, I should rest a bit...

LINQ Join between datatables, two untyped fields

I'm querying two databases and trying to join the result sets and query out of them using LINQ. It seems it would be an easy task, but without doing an explicit join I'm having major performance issues. When I do the explicit join, I am having trouble with VB syntax for making things explicit types. Working Code, Cleaned:
For Each CurrRow In ResultsA.Tables(15).Rows
CurrDate = CurrRow("Date")
CurrID = CurrRow("ID")
CurrVal = CurrRow("Val")
Dim ResultsB = From SMW In DataSetA.Tables(0).AsEnumerable() _
Where SMW("ID") = CurrScheduleID And SMW("Time") = CurrProfileDate _
Select UTC_TS = SMW("Time"), Value = (SMW("VALUE") / 1000), Time_Zone = SMW("Time_Zone"), ID = SMW("ID")
Dim CurrentResult As Object
Dim boolSchedDateFound As Boolean = False
For Each CurrentResult In ResultsB
If CurrentResult.Value <> CurrVal Then
'LogIntegrityCheckErrorRow()
End If
boolSchedDateFound = True
Next
Next
This takes FOREVER to run with 100,000 rows.
I've been trying to rewrite this as:
Dim MismatchRows = From TableAData In DataSetA.Tables(0).AsEnumerable() Join TableBData In DataSetB.Tables(15).AsEnumerable() _
On New With {.TableAID = Convert.ToInt32(TableAData("ID")), .TableATime = Convert.ToDateTime(TableAData("Date"))} _
Equals New With {.TableBDID = Convert.ToInt32(TableBData("ID")), .TableBTime = Convert.ToDateTime(TableBData("Time"))} _
Select .................. (Hard to clean up, but this isn't the part that's failing)
And I'm having a bear of a time with it. The fundamental problem is the lack of strong typing. I've looked, but there seems to be little advice because most people doing this build EF on the data. Which isn't a terrible idea, but would require a bunch of re-engineering. So. Problem in front of me, how do I remove the error:
'Equals' cannot compare a value of type '<anonymous type> (line 2641)' with a value of type '<anonymous type> (line 2642)'.
Thank you so much for your help.
Have you tried this?
Dim MismatchRows = From TableAData In ei _
Join TableBData In e2 On _
TableAData("ID") Equals TableBData("ID") And TableAData("Data") Equals TableBData("Time")
Select .......
db.tb_DeviceGeFenceDetail.Join(db.tb_InventoryLog, Function(gfd) gfd.DeviceID, Function(il) il.deviceId, Function(gfd, il) New From { _
gfd.GeFenceLat1, _
gfd.GeFenceLng1, _
gfd.GeFenceLat2, _
gfd.GeFenceLng2, _
il.deviceName, _
il.DeviceIcon, _
gfd.DeviceID, _
il.id _
}).ToList().Where(Function(y) intValues.Contains(y.id))
you can try joining tables something like this.

New to Linq; need to grab multiple values from single row

I'm trying to retrieve multiple columns from a datatable, but only from a single row -- and then set properties based on those results. I've figured out how to run multiple queries to obtain single columns at a time, but there must be a way to combine it all into one query.
Here's what I thought might work:
Dim colSettingsQry = From r In Me.GridProcColumnSettings.AsEnumerable _
Where r("DataFieldNm") = colNm _
Select New With _
{ _
.uniqueNm = r.Field(Of String)("UniqueNm").Single(), _
.sortExpression = r.Field(Of String)("SortExpression").Single(), _
.headerTxt = r.Field(Of String)("HeaderTxt").Single(), _
.headerStyleWidth = r.Field(Of String)("HeaderStyleWidth").Single(), _
.dataFormatString = r.Field(Of String)("DataFormatTxt").Single() _
}
gridCol.SortExpression = From c In colSettingsQry _
Select c.sortExpression
gridCol.HeaderText = From c In colSettingsQry _
Select c.headerTxt
... etc.
I'm guessing there's something pretty obvious that I'm missing - anyone have suggestions?
Thanks in advance.
I think you're looking for this:
Dim colSettingsQry = ... (your query)
Dim setting = colSettingsQry.FirstOrDefault()
If setting IsNot Nothing Then
gridCol.SortExpression = setting.SortExpression
gridCol.HeaderText = setting.HeaderText
...
EndIf
By FirstOrDefault you take the first element of a sequence if there is any, else Nothing.

mongodb query to find field - vb.net

How would I structure a query for mongodB to make a 'stored procedure' or make the request to select an id which is marked active and then delete that field immediately or mark it as inactive; whichever one has the better performance. Here is the collection structure:
db = server.GetDatabase("test")
siteCollection = db("test")
collection = db.GetCollection(Of BsonDocument)("siteids")
Dim book As BsonDocument = New BsonDocument() _
.Add("siteid", BsonValue.Create(BsonType.String)) _
.Add("active", BsonValue.Create(BsonType.String))
collection.Insert(book)
I found the java version and not sure if this will work and what is .net syntax
db.things.find( { x : 4 } , { j : 1 } )
This apparantly finds records where x = 4 but only return where j = 1 so I want one siteid where active = 'N'
Thanks; here is what I have come up with thus far:
' Dim squery = Query.EQ("active", "Y")
Dim squery = Query.EQ("active", "Y")
Dim ssort = SortBy.Null
Dim uupdate = Update.[Set]("active", "N")
Dim result = collection.FindAndModify(squery, ssort, uupdate)
' Dim dresult = collection.FindAs(Of BsonDocument)(squery)
Dim newSiteId As String = dresult.Count
As you can see the first line commented out I thought a simple select would be implemented but that comes back null. Then with the second last statement commented out that too returned value Null.

vb.net linq update Data

Hi Guys thanks for all the help on things. Im using linq and im able get get data ouf of it realy easy. but i seem to not be able to update the data. the program does not error on it and it looks likes it has updated but it does not save te changes.
Public Function UpdateAlarmsbyKey(ByVal objKey As Integer, ByVal IdNumber As String) As Boolean
Dim lqAlarms As New linqAlarmDumpDataContext
Dim GetAlrms = From r In lqAlarms.AlarmDrops _
Where r.Key = objKey _
Select r
For Each Calls In GetAlrms
If Calls.AlarmsHandled = "" Then
Calls.AlarmsHandled = IdNumber
Return True
Else
Calls.AlarmsHandled = Calls.AlarmsHandled & ":" & IdNumber
Return True
End If
Next
Return False
End Function
Try calling -
lqAlarms.SubmitChanges()
after you've updated the Calls.AlarmsHandled property. Also, your code is looping round a result set but will only change the first record it finds, is that the behaviour you wanted?