Searching through dataset

ahbenshaut

Well-known member
Joined
Oct 29, 2004
Messages
62
Location
Alaska
Programming Experience
5-10
Good Morning/Afternoon/Evening :)
I am trying to loop thru a dataset to find an exisiting employee. Here's the code I'm using once the dataset has been filled:

This is in a module so it can be accessed whenever:
Public winUser As String = Mid(GetCurrent().Name, 9, Len(GetCurrent().Name))

This is in the form code:
Dim filter As String = "NTLogin = 'bsmith'"
Dim matchrows() As DataRow = clsSecurity._dsAllEmployees.Tables("AllEmployees").Select(filter)
Dim row As DataRow
For Each row In matchrows
MessageBox.Show(row("Display Name").ToString & " " & row("Location").ToString)
Next

Everything works like it should if I leave the 'bsmith' in the first line hardcoded but I want to use the winUser as a variable since more than 1 person will be using the app. I know its just a syntax issue but I can figure it out.

Any help would be greatly appreciated
 
ahbenshaut said:
Good Morning/Afternoon/Evening :)
I am trying to loop thru a dataset to find an exisiting employee. Here's the code I'm using once the dataset has been filled:

This is in a module so it can be accessed whenever:
VB.NET:
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] winUser [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = Mid(GetCurrent().Name, 9, Len(GetCurrent().Name))[/SIZE]

This is in the form code:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] filter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "NTLogin = 'bsmith'"
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] matchrows() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow = clsSecurity._dsAllEmployees.Tables("AllEmployees").Select(filter)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] row [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] row [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] matchrows
MessageBox.Show(row("Display Name").ToString & " " & row("Location").ToString)
[/SIZE][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
Everything works like it should if I leave the 'bsmith' in the first line hardcoded but I want to use the winUser as a variable since more than 1 person will be using the app. I know its just a syntax issue but I can figure it out.

Any help would be greatly appreciated

This really isn't an ADO .NET question. It's just a concatenation issue. I'm just curious, what happens if you write your line like this:

VB.NET:
[COLOR=#0000ff]Dim[/COLOR][SIZE=2] filter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "NTLogin = " & winUser[/SIZE]

That should do it.
 
I tried that but I get an error that states Cannot find column [bsmith].
on this line:
Dim matchrows() As DataRow = clsSecurity._dsAllEmployees.Tables("AllEmployees").Select(filter)
 
You could also use the .concat method of the string class.
So you could say:

VB.NET:
Dim filter As String = String.Concat("NTLogin = ", winUser)

That might also fix the problem.
 
hmm..ok the line looks like so "NTLogin = bsmith" and I think its missing the single quotes around the bsmith but Im not sure how the syntax would be...
 
Ah, good call. This is how the syntax would go:

VB.NET:
Dim filter As String = "NTLogin = '" & winUser & "'"

There are single quotes in there, I swear. ;) filter should read as "NTLogin = 'bsmith'" now. :)
 
Back
Top