views:

47

answers:

2

I want to refer to a data cell, which if it is equals to some string, it will do something. The codes:

If ds.Tables(0).Rows(i)("Status") = "Reserved" Then
MessageBox.Show("Can't reserve")
End If

Is this the correct way to do this? Because I failed doing so..

+1  A: 

Check the return type of:

ds.Tables(0).Rows(i)("Status")

Also,

  • Is the case different (uppercase in db ??)

  • Check for leading/trailing spaces.

  • Is the field in database fixed-length

U might want to try trim-ing the string before comparing:

For Ex, in VB6 i might hav tried:

IF lower(trim$(<thedbqueryhere>))= "reserved" then

    msgBox("Can't reserve")

End if

GoodLUCK!!

CVS @ 2600Hertz

CVS-2600Hertz
do you have some reference to do it in VB.Net? i couldn't find any clear reference.
manuel
Plz try out magnifico's snippet above. That might *just* do the trick!!
CVS-2600Hertz
+1  A: 

You probably need to be checking the Value property of the cell.

Also here is the VB6 code by CVS @ 2600Hertz translated to VB.NET

Dim cell = ds.Tables(0).Rows(i)("Status")
If cell.Value.ToUpperInvariant().Trim() = "Reserved".ToUpperInvariant() Then
    MessageBox.Show("Can't Reserve")
End If
magnifico