Windows Search fails to find file when text converted to uppercase - vb.net

I have an odd problem with Windows Search engine. When I search for the Greek word, Όρος, in the Windows 10 Start menu search bar, I get the expected results.
When I search via VB.Net it fails to find any results. I've narrowed the issue to the final letter 'ς'. Removing it allows the search to succeed. Anyone know what the problem could be?
Dim t As String
t = UCase("Όρο") ' success
't = UCase("Όρος") ' fails
Dim connection = New OleDbConnection("Provider=Search.CollatorDSO;Extended Properties=""Application=Windows""")
Dim query1 = "SELECT System.ItemName FROM SystemIndex " +
"WHERE System.ItemName LIKE '%" & t & "%'"
connection.Open()
Dim Command = New OleDbCommand(query1, connection)
Dim r
Try
r = Command.ExecuteReader
Catch
Debug.WriteLine("Search failed!")
Return
End Try
Dim c = 0
While (r.Read())
c += 1
Debug.WriteLine(r(0))
End While
Debug.WriteLine("Total:" & c)

So it appears to be a bug in the library as far as I can tell.
After googling around, found the following related article,
https://channel9.msdn.com/coding4fun/articles/Searching-the-Desktop
which searched System.ItemNameDisplay instead of System.ItemName
Updated my query to use alternate field and it works.

Related

Get First & Last Name of All AD Accounts

I'm looking for the quickest and easiest way to retrieve all Active Directory account's first & last names. The intention is to have a string list which contains all names from the Active Directory, for the purpose of auto-completion in a textbox in a small Visual Basic application used for unlocking accounts.
Usage Scenario:
On form load the application generates the list of names from the AD. I'm expecting this to take around 10-15 seconds as there's 4,500 accounts on the AD. Each name is added to a string list for use with the auto completion.
The user types the name Garry into textbox1 and the auto complete suggests all Garry's in the AD, by using a string list. I know how to do this easily, I just dont know how to populate the list with user's names efficiently.
There's a lot of samples on accessing the AD, but none which show how to loop through it. I thought asking on here would help both myself and other users in a similar usage case.
The code I have so far for accessing a single account is shown below, however I need to loop through all AD accounts and retrieve their First & Last names.
Current Code to access single account:
'Domain is declared with the LDAP path
'UserName is declared with textbox1.text value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & Domain)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
ADSearch.Filter = ("(samAccountName=" & UserName & ")")
ADSearch.SearchScope = System.DirectoryServices.SearchScope.Subtree
Dim UserFound As System.DirectoryServices.SearchResult = ADSearch.FindOne()
If Not IsNothing(UserFound) Then
Log.AppendLine("Account found, loading checks...")
Dim Attrib As String = "msDS-User-Account-Control-Computed"
Dim User As System.DirectoryServices.DirectoryEntry
User = UserFound.GetDirectoryEntry()
User.RefreshCache(New String() {Attrib})
'Display user account details
txtLogin.Text = User.Properties("userPrincipalName").ToString
txtName.Text = User.Properties("givenName").ToString & " " & User.Properties("sn").ToString
else
'User not found
end if
Any help would be much appreciated, even in C#.
You can use the same ADEntry variable as above and do something like this. This only adds a user to the list if they have both a first and last name.
Dim listNames As New AutoCompleteStringCollection
Using ADSearch As New DirectoryServices.DirectorySearcher(ADEntry, "(&(objectCategory=person)(objectClass=user))", {"givenName", "sn"}, DirectoryServices.SearchScope.Subtree)
For Each user As DirectoryServices.SearchResult In ADSearch.FindAll
Try
listNames.Add(user.GetDirectoryEntry.Properties("givenName").Value.ToString + " " + user.GetDirectoryEntry.Properties("sn").Value.ToString)
Catch ex As Exception
End Try
Next
End Using
With TextBox1
.AutoCompleteCustomSource = listNames
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.AutoCompleteSource = AutoCompleteSource.CustomSource
End With

Updating row in database using vb.net

I am trying to update and save a row of a database table. I have used a version of this code to just populate a GridView and it works, so I am assuming it has something to do with my SQL statment; I do not get an error, the table just does not update. On the page load event I have the textboxes being populated by the information of the row, and I have a global variable, named 'temp', that will save the title of the row so I can use it in the button's click event. The error I am getting states that I have not given a value for one of my required parameters. My Locals tab on the debugger shows that every variable has a value, though the one I try to update is not the new data but still the old data.
I have looked at several examples and I cannot find the problem though. Thank you for any assistance.
Protected Sub btnSave_Click(sender As Object, e As EventArgs)
Dim strTitle As String = txtTitle.Text
Dim strConsole As String = txtConsole.Text
Dim strYear As String= txtYear.Text
Dim strPurchase As String = calDate.SelectedDate.ToString
Using con As OleDbConnection = New OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "DATA SOURCE=" + Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "App_Data", "db1.accdb"))
Dim cmd As OleDbCommand = New OleDbCommand()
cmd.CommandText = Convert.ToString("UPDATE Video_Games SET Title = #title, Console = #Console, Year_Released = #Year_Released, Purchase = #Purchase WHERE Title=" & temp)
cmd.Connection = con
cmd.Parameters.AddWithValue("#Title", strTitle)
cmd.Parameters.AddWithValue("#Console", strConsole)
cmd.Parameters.AddWithValue("#Year_Released", strYear)
cmd.Parameters.AddWithValue("#Purchase", strPurchase)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
Server.Transfer("Form.aspx", True)
End Sub
I have also tried the have my where statement as: WHERE Title='" & temp & "'") Though this does not work either.
This is the details of the Error message
I changed you commandText as seen below and created a blank database with a table named just like yours and the update worked
cmd.CommandText = "UPDATE Video_Games SET Title = #title, Console = #Console, Year_Released = #Year_Released, Purchase = #Purchase WHERE Title='" & temp & "'"
I set my variable for Title = Super Mario Bros and then the temp variable to Wario World. I had a record in my database with the title of Wario World, and running the update changed the title to Super Mario Bros.
Check if you temp variable is different from your #title variable. Also check that you have the record int the table for your temp variable title
Thank you all for your assistance, This is such a wonderful community.
The problem, I found out, does not even have to do with the button's click event, it had to do with the page load event. Since on page load the row's information is loaded and populated into the textboxes, when the button is clicked to update the fields, the page load event triggers again and reloads the old information into fields, essentially saving the old information instead of the new. My fix was to create an If Not IsPostBack Then statement that encapsulates my on page load code. Therefore the code does not get saved when the button is pressed. Another this, I did not need the temp variable, using WHERE Title='" + strTitle + "'" worked. Hopefully this helps other people stuck on a similar problem!
Using dates in a where clause is always ify as they are floating point numbers and may not match equally. I'd try and round them or convert them to strings before comparison, e.g. something along these lines:
UPDATE Video_Games SET Title = #title, Console = #Console, Year_Released = #Year_Released, Format(Purchase, ""m/d/yyyy"") = Format(#Purchase, ""m/d/yyyy"") WHERE Title = #Title

How do I display the value of a shared parameter using an Element collector in Revit?

Thanks in advance for the help. I have no idea what I'm doing wrong and it's becoming very frustrating. First, a little background...
Program: Revit MEP 2015
IDE: VS 2013 Ultimate
I have created a Shared Parameter file and added the parameters in that file to the Project Parameters. These parameters have been applied to Conduit Runs, Conduit Fittings, and Conduits.
I'm using VB.NET to populate the parameters with no issue. After the code runs, I can see the expected text applied in the elements property window. Here is the code used to populate the values:
Populate:
Dim p as Parameter = Nothing
Dim VarName as String = "Parameter Name"
Dim VarVal as String = "Parameter Value"
p = elem.LookupParameter(VarName) <-- elem is passed in to the function as an Element
If p IsNot Nothing Then
p.Set(VarVal)
End if
Here's where I run into the error. When I attempt to retrieve the value, I am able to get the parameter by the parameter's definition name, but the value is always blank. Here is the code used to retrieve...
Try
For Each e As Element In fec.OfCategory(BuiltInCategory.OST_ConduitRun)
sTemp = sTemp & "Name: " & P.Definition.Name & vbCrLf & "Value: " & P.AsString & vbCrLf & "Value As: " & P.AsValueString & vbCrLf & vbCrLf
sTemp2 = sTemp2 & "Name: " & GetParamInfo(P, doc)
Next
MessageBox.Show(sTemp)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
The message box shows all of the parameter names correctly, and for the Revit parameters it gives me a value. The Shared parameters, however, only show the parameter names, the values are always blank. Is there another way that I'm supposed to be going about this? Oddly, I'm able to see the shared parameter values if I use a reference by user selection like so...
Dim uiDoc As UIDocument = app.ActiveUIDocument
Dim Sel As Selection = uiDoc.Selection
Dim pr As Reference = Nothing
Dim doc As Document = uiDoc.Document
Dim fec As New FilteredElementCollector(doc)
Dim filter As New ElementCategoryFilter(BuiltInCategory.OST_ConduitRun)
Dim sTemp As String = "", sTemp2 As String = ""
Dim elemcol As FilteredElementCollector = fec.OfCategory(BuiltInCategory.OST_ConduitRun)
Dim e As Element = Nothing, el As Element = Nothing
Dim P As Parameter
pr = Sel.PickObject(ObjectType.Element)
e = doc.GetElement(pr)
For Each P in e.Paramters
sTemp = sTemp & "Name: " & P.Definition.Name & vbCrLf & "Value: " & P.AsString & vbCrLf & "Value As: " & P.AsValueString & vbCrLf & vbCrLf
sTemp2 = sTemp2 & "Name: " & GetParamInfo(P, doc)
Next
MessageBox.Show(sTemp)
With the method above, when the user selects the object directly, I can see the values and the names of shared parameters. How are they different?
Is there some sort of binding that I should be looking at when the value is set to begin with? Thanks in advance for everyone's help.
Regards,
Glen
Holy Bejeesus... I figured it out, but I'm not sure why the methods are that different from each other... if anyone had any insight, that'd be great.
I wanted to post the answer here, just in case anyone else is fighting with the same thing, so... you can see the method I was using to try to read the parameters above. In the method being used now there are only a couple of things that are different... 1) An element set... 2) An active view Id was added as a parameter to the FilteredElementCollector... 3) A FilteredElementIterator was implemented.
As far as I can tell it's the iterator that's making it different... can anyone explain what it's doing differently?
Below is the method that actually works...
Public Sub Execute(app As UIApplication) Implements IExternalEventHandler.Execute
Dim prompt As String = ""
Dim uiDoc As UIDocument = app.ActiveUIDocument
Dim doc As Document = uiDoc.Document
Dim ElemSet As ElementSet = app.Application.Create.NewElementSet
Dim fec As New FilteredElementCollector(doc, doc.ActiveView.Id)
Dim fec_filter As New ElementCategoryFilter(BuiltInCategory.OST_Conduit)
fec.WhereElementIsNotElementType()
fec.WherePasses(fec_filter1)
Dim fec_i As FilteredElementIterator = fec.GetElementIterator
Dim e As Element = Nothing
fec_i.Reset()
Using trans As New Transaction(doc, "Reading Conduit")
trans.Start()
While (fec_i.MoveNext)
e = TryCast(fec_i.Current, Element)
ElemSet.Insert(e)
End While
Try
For Each ee As Element In ElemSet
GetElementParameterInformation(doc, ee)
Next
Catch ex As Exception
TaskDialog.Show("ERROR", ex.Message.ToString)
End Try
trans.Commit()
End Using
End Sub
At any rate, thanks for any help that was offered. I'm sure it won't be the last time that I post here.
Regards,
Runnin

Runtime Error 3061 Help (ms access)

I've been wracking my brain trying to find what is wrong with this query and I just don't see it. I'm trying to open a record set and I keep getting runtime error 3061: "Too few parameters: Expected 1."
Here's my code...
Dim ansRs As Recordset
Dim qRs As Recordset
Dim ansQuery As String
Dim qQuery As String
Dim i As Integer
qQuery = "Select * From TrainingQuizQuestions Where TrainingQuizID = (Select TrainingQuiz.TrainingQuizID From TrainingQuiz Where QuizName = Forms!MainMenu!txtVidName);"
ansQuery = "Select * From TrainingQuizQuestAns"
Set qRs = CurrentDb().OpenRecordset(qQuery)
Set ansRs = CurrentDb().OpenRecordset(ansQuery)
I'm getting the error from the line "Set qRs = CurrentDb().OpenRecordset(qQuery)". I copied and pasted that query into access and ran it and it returned exactly what I want to get in my record set, yet when I run it in VBA I get the error. Am I missing something really simple? Any help would be greatly appreciated.
First ensured that your form is open, then put the form reference outside your quotes.
qQuery = "Select * From TrainingQuizQuestions Where TrainingQuizID = " _
& "(Select TrainingQuiz.TrainingQuizID From TrainingQuiz Where QuizName = '" _
& Forms!MainMenu!txtVidName) & "';"
The form value is not available to a recordset used in VBA.

Is it possible to submit data into a SQL database, wait for that to finish, and then return the ID generated from SQL, using Classic ASP?

I have an ASP form that needs to submit data to two different systems. First the data needs to go into an MS SQL database, which will get an ID. I then need to submit all that form data to an external system, along with that ID.
Pretty much everything in the code works just fine, the data goes into the database, and the data will go to the external system. The problem is I am not getting my ID back from SQL when I execute that query. I am under the impression this is happening because of how fast everything occurs in the code. The database is adding it's row at the same time my post page runs it's query to get the ID back, I think.
I need to know of a way to wait until SQL finished the insert or wait for a specific amount of time maybe. I already tried using the hacks to "sleep" with ASP, that did not help.
I am sure I could accomplish this in .Net, my background is more .Net than ASP, but this is what I have to work with on my current project.
Any ideas?
EDIT: Code from the the function writing to the DB.
driis - That was my understanding of how this should be working, but my follow up query for the ID returns nothing, so my though is that the row hasn't finished being inserted or updated yet. Maybe I am wrong on that, if so, that complicates this more. :(
Either way here is the code from the function to update the DB. Mind you this code is inherited, the rest of my project is being written by me, but I am stuck using these functions from a previous developer.
Sub DBWriteResult
Dim connLeads
Dim sSQL
Dim rsUser
Dim sErrorMsg
Dim sLeads_Connection
' Connect to the Leads database
' -------------------------------------------------------------------
sLeads_Connection = strDatabaseConnection
Set connLeads = CreateObject("ADODB.Connection")
connLeads.Provider = "SQLOLEDB.1"
On Error Resume Next
connLeads.Open sLeads_Connection
If Err.number <> 0 Then
' Bad connection display error
' -----------------------------------------------------------------
Response.Write "Database Write Error: 001 Contact Programmer"
Set connLeads = Nothing
Exit Sub
Else
' Verify the transaction does not already exist.
' -----------------------------------------------------------------------
Set rsUser = Server.CreateObject("ADODB.Recordset")
rsUser.LockType = 3
rsUser.CursorLocation = 3
sSQL = "SELECT * "
sSQL = sSQL & " FROM Leads;"
rsUser.Open sSQL, connLeads, adOpenDynamic
Response.Write Err.Description
If Err.number = 0 Then
' Add the record
' -----------------------------------------------------------
rsUser.AddNew
rsUser.Fields("LeadDate") = Date()&" "&Time()
rsUser.Fields("StageNum") = ESM_StageNum
rsUser.Fields("MarketingVendor") = ESMSourceData
rsUser.Fields("FirstName") = ESM_FirstName
rsUser.Fields("Prev_LName") = Request.Form ("Prev_LName")
rsUser.Fields("LastName") = ESM_LastName
rsUser.Fields("ProgramType") = ESM_ProgramType
rsUser.Fields("ProgramofInterest") = ESM_ProgramofInterest
rsUser.Fields("Phone1") = Phonenumber
rsUser.Fields("Phone2") = ESM_Phonenumber2
rsUser.Fields("Address1") = ESM_Address
rsUser.Fields("Address2") = ESM_Address2
rsUser.Fields("City") = ESM_City
rsUser.Fields("State") = ESM_State
rsUser.Fields("Region") = ESM_Region
rsUser.Fields("Zip") = ESM_Zip
rsUser.Fields("Country") = ESM_Country
rsUser.Fields("Email") = ESM_Email
rsUser.Fields("MilitaryBranch") = ESM_MilitaryBranch
rsUser.Fields("MilitaryStatus") = ESM_MilitaryStatus
rsUser.Fields("BestTimeToCall") = ESM_BestTimeToCall
rsUser.Fields("DateofBirth") = ESM_DateofBirth
rsUser.Update
Else
' There was an error
Response.Write "There was an error. Error code is: "&Err.number&" "&Err.Desc
End if
End If
' Close the recordset
' ---------------------------------------------------------------
Call rsUser.Close
Set rsUser.ActiveConnection = Nothing
Set rsUser = Nothing
' Destroy the connection to the database
' -------------------------------------------------------------------
Set connLeads = Nothing
End Sub
It sounds like you're trying to do this:
Insert some data in DB 1
Retrieve an ID from the inserted data
Send data + the ID to DB 2
It's been a good five years but I believe it looked something like this:
dim connStr1
connStr1 = "[connection string 1]"
dim conn1
set conn1 = server.createobject("adodb.connection")
conn1.open connStr1
dim sql
sql = " SET NOCOUNT ON " & vbCrLf & _
" INSERT FOO (a, b, c) VALUES (1, 2, 3) " & vbCrLf & _
" SET NOCOUNT OFF " & vbCrLf & _
" SELECT SCOPE_IDENTITY() "
dim rs
set rs = conn1.execute(sql)
rs.close
dim id
set id = CInt(rs(0))
conn1.close
dim connStr2
connStr2 = "[connection string 2]"
dim conn2
set conn2 = server.createobject("adodb.connection")
conn2.open connStr2
conn2.execute("INSERT FOO (id, a, b, c) VALUES (" & id & ", 1, 2, 3)")
conn2.close
Good luck, and get off my lawn!
Ok, so I figured this one out. The problem was insane, a typo. I am spoiled with .Net and the fact that if I use a variable that doesn't really exist, I get errors. I guess ASP doesn't care so much.
On the up side, driis was correct. The code does not continue until the database transaction is completed. That was my major concern, that had incorrectly assumed that was the case. I am glad I was right.
Thanks for the help, and hopefully the next time I post it'll be something better than a tyop.
;)