Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Jul 20, 2018 1:41 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Pretty straight forward question
PostPosted: Wed Apr 17, 2013 12:23 pm 
Offline

Joined: Sun Oct 21, 2012 11:59 pm
Posts: 21
I'm trying to make my program check if the data exists in the database, based on user impute from an editfield, and if it does, to execute a set of actions. I'm kinda stuck :|


Top
 Profile  
Reply with quote  
 Post subject: Re: Pretty straight forward question
PostPosted: Wed Apr 17, 2013 1:27 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
SELECT COUNT(*) as CNT FROM yourtable WHERE <code the criteria here>


IF RS.FIELD("CNT").integervalue>0 then the data already exists

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Pretty straight forward question
PostPosted: Wed Apr 17, 2013 2:53 pm 
Offline

Joined: Sun Oct 21, 2012 11:59 pm
Posts: 21
I worded that wrong sorry bout that. What I'm trying to do is have a sort of log in window thing. User types in an ID, program checks if the ID is in the database, and logs them in if true, or a message box says an error if false.

I need more coffee in the morning before I start talking to people...


Top
 Profile  
Reply with quote  
 Post subject: Re: Pretty straight forward question
PostPosted: Wed Apr 17, 2013 3:24 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Ok.... same answer

if CNT=0 then ID does not exist... if CNT>=1 then it does.

sql="SELECT COUNT(*) as CNT FROM yourtable WHERE code_field="+textedit1.text


assuming user enters data in textedit1

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Pretty straight forward question
PostPosted: Wed Apr 17, 2013 6:21 pm 
Offline

Joined: Sun Oct 21, 2012 11:59 pm
Posts: 21
I'm getting an error when running this;

Dim rs As RecordSet

database.SQLExecute( "SELECT COUNT(*) as CNT FROM table WHERE column='" + imputfld.text + "'" )

If rs.Field("CNT").IntegerValue > 0 then
1Window.Visible = False
2Window.Visible = True
Else
MsgBox("User does not exist.")
End If


It stops at the beginning of the loop with "NilObjectExecption" as the error.


Top
 Profile  
Reply with quote  
 Post subject: Re: Pretty straight forward question
PostPosted: Wed Apr 17, 2013 6:33 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
is your table actually named "table"????
and the column with the id is actually named "column"?????

not very descriptive if they are.

Also it would be prudent to ALWAYS include some level of error checking between the execution of the query, and any attempt to retrieve data from that query


Not to mention you are doing it incorrectly to begin with...... Notice your code has no connection between RS and the SQLExecute?

Dim rs As RecordSet

rs=database.SQLSelect( "SELECT COUNT(*) as CNT FROM table WHERE column='" + imputfld.text + "'" )

If database.Error Then
msgbox "your query failed.. do something"
Else

If rs.Field("CNT").IntegerValue > 0 then
1Window.Visible = False
2Window.Visible = True
Else
MsgBox("User does not exist.")
End If

end if

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group