开发者

How to refer to a text in an Ms Access table?

开发者 https://www.devze.com 2022-12-27 21:05 出处:网络
I want to refer to a data cell, which if it is equals to some string, it will do something. The codes:

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") =开发者_JAVA技巧 "Reserved" Then
MessageBox.Show("Can't reserve")
End If

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


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消