Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 14th, 2007, 02:17 AM
Registered User
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default What am I not seeing

I am using vb.net2003.
Trying to load a datset and then compare a value. If conditions are satisfied do some thing
here is the code

mySearchString = "Select animalID,Status, Type from tblInventory where animalID=" & txtanimalID.Text
            DsInventory1.Clear()
            daInventory.SelectCommand.CommandText = mySearchString
            daInventory.Fill(DsInventory1)

"Data set is loading successfully No problem. I have put a message.box.show(DsInventory1.tblInventory(0).Type )for testing purposes which shows inventory item is CAT type) "


if DsInventory1.tblInventory(0).Type="CAT" then

subCat()
elseif DsInventory1.tblInventory(0).Type="DOG" then

subDog()

else messagebox.show("no pets in stock")


program zips thru and messagebox no pets in stock comes up

why my conditon is not matching. VB GURUs please help me quick.

Raj






rSd
 
Old July 14th, 2007, 12:12 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Have you stepped thru the code to see what the actual values for .Type are? Can you find some that *should* match but aren't?

-Peter
 
Old July 15th, 2007, 12:32 AM
Registered User
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes I am geeting .type = CAT

   mySearchString = "Select animalID,Status, Type from tblInventory where animalID=" & txtanimalID.Text
            DsInventory1.Clear()
            daInventory.SelectCommand.CommandText = mySearchString
            daInventory.Fill(DsInventory1)

aType = DsInventory1.tblInventory(0).Type
Messagebox.show(aType)
it gives me output of CAT
if DsInventory1.tblInventory(0).Type="CAT" then

subCat()
elseif DsInventory1.tblInventory(0).Type="DOG" then

subDog()

else messagebox.show("no pets in stock")


program zips thru and messagebox no pets in stock comes up

why my conditon is not matching. VB GURUs please help me quick.

Raj


rSd
 
Old July 15th, 2007, 09:03 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

How is your table defined? Is it possible that the type field is a char field that is more than 3 characters? Thus the actual value coming back is something like:
   "CAT_____" ( _ character represents a space)
which is not equal to
   "CAT"

Maybe you need to trim the database value before you compare.

Better still... "Type" type db fields are better suited as integers that relate to a lookup table. Then you run into fewer problems trying to compare them.

-Peter
 
Old July 15th, 2007, 12:04 PM
Registered User
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You hit right on the nail. your suggestion worked.

First 2 record had problem
and i was testing by first 2 records ID.
Once I deleted first 2 records program started working.


Thank you very much

rSd









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.