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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing data reader value to text control string

Status
Not open for further replies.

jwilso

Programmer
Jun 29, 2004
4
US
I am positive this piece of code was working the other day and can't figure out why it isn't finding values to be equal.

cmd.CommandText = "SELECT * FROM Collection WHERE CollectionType = '" & Me.Cmb_CollectionType.Text & "'"
cmd.Connection = SqlConnection1
SqlConnection1.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)

While dr.Read
For x As Integer = 1 To 15
If dr.Item(x).ToString = Me.Txt_Attribute.Text.TrimEnd(" ") Then

Thanks in advance,

-JW
 
Looks right. Try converting your comparision strings ToLower() as well so that different capitalizations don't return false.

because "Cat" and "cat" are not equal, etc.

Just a thought
 
I tried ToLower and trimed the end of both strings and they still evaluate false. Any other ideas?

-JW
 
Did you use the Immediate Window and look at the values of dr.Item(x).ToString() and Me.Txt_Attrive.Text.TrimEnd(" ")

put a breakpoint on you if statement then look and see what they are.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top