vendredi 11 septembre 2015

How to query a single value from a datatable using linq in vb.net

I'm trying to query a value from a datable in vb using a linq query but am getting several errors.

here's my code:

For Each cl In clients
Dim cn As DataTable
    cn = getClients() #datatable with two columns, client code (cln_idck) and client name (cln_name)
Dim clientname As String
clientname = From cntable In cn Where cntable.Item("cln_idck") = cl Select (cntable.Item("cln_name")).ToString()

#do something   
Next

I'm just trying to grab the client name and put it into the string variable clientname using the client code to search. The above code gives me an error.

"range variable name cannot match the name of a member of the "object" class"

Any ideas why this isn't working?

Thanks for the help!

Rafael

update:

client is a list(of string) that has the client codes

Dim clients As New List(Of String)
    clients.Add("Cln1")
    clients.Add("Cln2") #etc.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire