New topic: Unable to use return value of SQL count
<http://forums.realsoftware.com/viewtopic.php?t=46562> Page 1 of 1 [ 8 posts ] Previous topic | Next topic Author Message McDian Post subject: Unable to use return value of SQL countPosted: Mon Jan 14, 2013 4:15 pm Joined: Fri Sep 14, 2007 5:00 pm Posts: 383 Hello, long time since I have had to ask for help... and I need it yet once again. I have an SQL statement that counts records based on specific criteria. Simple and easy peasey. When I step through the code and look at the returned RecordSet I can see a value is present. In the Contents of the RecordSet I see this Name: COUNT(yerPer) Value: 8 so there is a value there. BUT when I try to put the value into use I get a NilObjectException thrown. Here is where I am trying to use the value. recCnt.Field("recCnt").IntegerValue = recSet.IdxField(0).IntegerValue I have also tried this: recCnt.Field("recCnt").IntegerValue = recSet.IdxField(1).IntegerValue And neither one allows me to use the count value that I know is contained in the RecordSet. What am I doing wrong? Top Surfer_Joe Post subject: Re: Unable to use return value of SQL countPosted: Mon Jan 14, 2013 4:28 pm Joined: Mon Mar 03, 2008 1:29 am Posts: 12 May be try, Dim i As Integer = recSet.IdxField(0).IntegerValue Top McDian Post subject: Re: Unable to use return value of SQL countPosted: Mon Jan 14, 2013 4:57 pm Joined: Fri Sep 14, 2007 5:00 pm Posts: 383 Nope... still getting a NilObjectException. Below are image sequences of the problem. Top kermit Post subject: Re: Unable to use return value of SQL countPosted: Mon Jan 14, 2013 5:03 pm Joined: Mon May 30, 2011 12:56 am Posts: 590 Is COUNT(yerPer) actually a field name in the record set? I would have expected it to be aliased in the query select count(yerPer) CountYerPer from table1 where .... In which case the field would be called CountYerPer Secondly, is the count variable the first variable in the select statement? If the select was select some name,count(yerPer) .... then you should be looking at field (1) not (0) So... what is your actual select statement, and did you check for a database error after getting the data? Top McDian Post subject: Re: Unable to use return value of SQL countPosted: Mon Jan 14, 2013 5:17 pm Joined: Fri Sep 14, 2007 5:00 pm Posts: 383 I have a module with a method specifically for record counting. Here are the detail of this method, I will keep the code pared down to the keep pieces Method Name: mthRecordCounts Parameters: stTbleId As String, stMetId As String Return Type: RecordSet Dim recCounts As RecordSet recCounts = dbFaserBase.SQLSelect("SELECT COUNT(yerPer) FROM tblHistory WHERE yerPer='" + stMetId + "'") Return recCounts Now we go to the calling form Dim recSet As RecordSet recSet = modSelect.mthRecordCounts("tblHistory",aAry(B)) Top McDian Post subject: Re: Unable to use return value of SQL countPosted: Mon Jan 14, 2013 5:33 pm Joined: Fri Sep 14, 2007 5:00 pm Posts: 383 So I am skipping this way of doing things until later... need to keep moving forward as I have a lot of records to copy... I'll check back later see if there is an answer as to why I can't get this working right. Top timhare Post subject: Re: Unable to use return value of SQL countPosted: Mon Jan 14, 2013 6:15 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 11982 Location: Portland, OR USA I see in your image that EOF is true, meaning you have already stepped past the record containing the value. Top npalardy Post subject: Re: Unable to use return value of SQL countPosted: Mon Jan 14, 2013 6:23 pm Real Software Engineer Joined: Sat Dec 24, 2005 8:18 pm Posts: 7674 Location: Canada, Alberta, Near Red Deer Surfer_Joe wrote:May be try, Dim i As Integer = recSet.IdxField(0).IntegerValue Dim i As Integer = recSet.IdxField(1).IntegerValue recordset fields are always numbered starting at 1 _________________ My web site Great White Software RBLibrary.com REALbasic learning Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 8 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
