Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datatable Select method returns 0 rows; string contains variables? 1

Status
Not open for further replies.

fsteeman

Programmer
Jul 17, 2002
103
DK
Hello all,

Now here's a head-scratcher... Whenever I call the select string below, no rows are returned:

[navy]
locRows = Me.GMDB2DataSet.AreaNames.Select("AreaCode = '" & CInt(srcRow.Item("Komm_nr")) & "' AND AreaCodeStandard = 1")
[/navy]

However, when I simply write:

[navy]
locRows = Me.GMDB2DataSet.AreaNames.Select("AreaCode = '765' AND AreaCodeStandard = 1")
[/navy]

Then it does return the rows I want to select. But the select strings are exactly the same! (I know because I checked) Is there some secret law forbidding the use of composite strings in select methods? I am stumped...

Fedor Steeman
Geological Museum Copenhagen
Denmark
 
When building filter strings...do the following.

1) For Integer fields dont wrap quotes around them, and convert them to String
2) For String Fields think about trailing spaces.

Try this...(assumes AreaCode and AreaCodeStandard are both Integer fields in your Datatable)
Code:
.Select("AreaCode = " & srcRow("Komm_nr").ToString & " AND AreaCodeStandard = 1")


Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
Thanks, but AreaCode is not an integer, it's a string field.

Anyways, I solved the problem myself using this code:

[navy]
strselect = String.Format("AreaCode = '{0}' AND AreaCodeStandard = 1", CInt(srcRow.Item("Komm_nr")))
locRows = Me.GMDB2DataSet.AreaNames.Select(strselect)
[/navy]

Apparanly the Format-method of the string class is the way forward. However, I am still at a loss why it wouldn't accept simple concatenation. VB6 did...

Cheers,

Fedor Steeman
Geological Museum Copenhagen
Denmark
 
Well, waddaya know! The tostring-method works too and is a lot of a heck simpler! Thanks for the tip!

Fedor Steeman
Geological Museum Copenhagen
Denmark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top