Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 3 Jahren
Letzter Beitrag:
vor 3 Jahren
Beteiligte Autoren:
Yogi Yang, Arie, Al, ICI, David Egan

WM17 - no browse was initialized

Startbeitrag von Yogi Yang am 24.02.2015 05:32

I am trying to retrieve data from DB and populate it in a Looper using following code:

dsMyData is Data Source
sSQL is string
bRetCode is boolean
I is int

//Variables to store Student info for Populating Looper
nStudentID is int
sStudentName is string
sStudentNum is string
bIsPresent is boolean
nStudentDivID is int
sStudentDivName is string

IF COMBO_SubjectType = "Optional" THEN
//Means Optional Subject
sSQL = "SELECT DISTINCT sm_id, em_serial_no, sm_fname, sm_lname, em_div_id, div_division_name FROM student_master AS sm INNER JOIN enrollment_details AS em ON (sm_id = em_sm_id) INNER JOIN div_master ON (em_div_id = div_id) WHERE (em_std_id = " + COMBO_Standards..StoredValue + " AND em_sub_id = " + COMBO_Subject..StoredValue + ") ORDER BY em_serial_no;"
ELSE
sSQL = "SELECT DISTINCT sm_id, em_serial_no, sm_fname, sm_lname, em_div_id, div_division_name FROM student_master AS sm INNER JOIN enrollment_details AS em ON (sm_id = em_sm_id) INNER JOIN div_master ON (em_div_id = div_id) WHERE (em_div_id = " + COMBO_Division..StoredValue + " AND em_std_id = " + COMBO_Standards..StoredValue + " AND em_sub_id = " + COMBO_Subject..StoredValue + ") ORDER BY em_serial_no;"
END

bRetCode = HExecuteSQLQuery(dsMyData,hQueryDefault,sSQL)

IF bRetCode = True THEN
IF HNbRec(dsMyData) > 0 THEN
HReadFirst(dsMyData)
I = 1
Info(HListItem(dsMyData,hLstAll))
FOR I = 1 _TO_ HNbRec(dsMyData)
nStudentID = dsMyData.sm_id
sStudentName = dsMyData.em_serial_no
sStudentNum = dsMyData.sm_fname + " " + dsMyData.sm_lname
bIsPresent = True
nStudentDivID = dsMyData.em_div_id
sStudentDivName = dsMyData.div_division_name
Info(nStudentID,sStudentName,sStudentNum,sStudentDivName) // 0 THEN
ELSE //IF bRetCode = True THEN
Error("Error ",HErrorInfo())
END //IF bRetCode = True THEN

But...but... is does not work. It gives the error No browse was initialized. I have been banging my head for last 2 days trying to get this code up and running without success. I am using SQLite as this is an Android app as back end.

Can someone please help here...

TIA

Yogi Yang

Antworten:

Hi Yogi
Not sure but my guess would be that the loop To HnbRec(dsMyData) is clearing the buffer so the HReadNext fails

I would change the loop as follows

HReadFirst(dsMyData)
i= 1
WHILE HFound(dsMyData)
//Do your thing
HReadNext(dsMyData)
END


HTH

David

von David Egan - am 24.02.2015 06:14
I don't think so because this WHILE code is also not working

WHILE NOT HOut(dsMyData)
//Do your thing
HReadNext(dsMyData)
END



TIA

Yogi Yang

von Yogi Yang - am 24.02.2015 06:43
Yogi .
If hNbRec() return more then 0 the you have your data, THEN
use or WHILE() or FOR (dont combine it)
You don't need "I" and hNbRec() to read data source.
if you use FOR then Hreadnext() is intruder. Don't use it. Use this code below

FOR EACH dsMyData

NEXT

or

HreadFist(dsMyData)
WHILE Hout(dsMyData) = False

HreadNext(dsMyData)
END

You can also try this.
nPosition is int = LooperAdd(LOOP_StudentPresenceData)
LOOP_StudentPresenceData[nPosition].ATT_StudentID = nStudentID
LOOP_StudentPresenceData[nPosition].ATT_StudentName = sStudentName
and so on...

von ICI - am 24.02.2015 06:50
ICI,

I tried is like this

WHILE HOut(dsMyData) = False
nStudentID = dsMyData.sm_id
sStudentName = dsMyData.em_serial_no
sStudentNum = dsMyData.sm_fname + " " + dsMyData.sm_lname
bIsPresent = True
nStudentDivID = dsMyData.em_div_id
sStudentDivName = dsMyData.div_division_name
Info(nStudentID,sStudentName,sStudentNum,sStudentDivName)

//Add Item to Looper
nPosition is int = LooperAdd(LOOP_StudentPresenceData)
LOOP_StudentPresenceData[nPosition].ATT_StudentID = nStudentID
LOOP_StudentPresenceData[nPosition].ATT_StudentName = sStudentName
LOOP_StudentPresenceData[nPosition].ATT_StudentNum = sStudentNum
LOOP_StudentPresenceData[nPosition].ATT_StudentPresent = bIsPresent
LOOP_StudentPresenceData[nPosition].ATT_StudentDivID = nStudentDivID
LOOP_StudentPresenceData[nPosition].ATT_StudentDivName = sStudentDivName
HReadNext(dsMyData)
END


But then the while loop is never executed.

von Yogi Yang - am 24.02.2015 11:11
If I use the For Loop like this

nTotalStudents = HNbRec(dsMyData)
IF nTotalStudents > 0 THEN
HReadFirst(dsMyData)
FOR I = 1 _TO_ nTotalStudents
nStudentID = dsMyData.sm_id
sStudentName = dsMyData.em_serial_no
sStudentNum = dsMyData.sm_fname + " " + dsMyData.sm_lname
bIsPresent = True
nStudentDivID = dsMyData.em_div_id
sStudentDivName = dsMyData.div_division_name

Info(nStudentID,sStudentName,sStudentNum,sStudentDivName)
//I get error after the above code line is executed!
//Add Item to Looper
nPosition is int = LooperAdd(LOOP_StudentPresenceData)
LOOP_StudentPresenceData[nPosition].ATT_StudentID = nStudentID
LOOP_StudentPresenceData[nPosition].ATT_StudentName = sStudentName
LOOP_StudentPresenceData[nPosition].ATT_StudentNum = sStudentNum
LOOP_StudentPresenceData[nPosition].ATT_StudentPresent = bIsPresent
LOOP_StudentPresenceData[nPosition].ATT_StudentDivID = nStudentDivID
LOOP_StudentPresenceData[nPosition].ATT_StudentDivName = sStudentDivName
HReadNext(dsMyData)
END //FOR I = 1 _TO_ nTotalStudents

BTN_SaveAttendence..Visible = True
CBOX_SelectAll..Visible = True
CBOX_SelectAll..Value = True
END //IF nTotalStudents > 0 THEN


Now I am getting the error message which is in a bit more elaborate form.

It is: No browse was initialized for on file.

What does this mean?

Do we have to initialize Browse for a field? If Yes then how?

TIA

Yogi Yang

von Yogi Yang - am 24.02.2015 11:22
Yogi Yang,
I sometimes test a query in a separate sqlite tool or viewer to see if it returns records. Apart from WM, because it is sometimes a bit unclear how WM changes the query.

von Arie - am 24.02.2015 11:32
Arie,

That is right. In fact I build my queries using SQLite Manager tool which allows me to build queries and test them.

So my queries are proper and they do return data.

TIA

Yogi Yang

von Yogi Yang - am 24.02.2015 11:45
Isn't your for-loop running 1 too many, because you already start with a hreadfirst?
FOR I = 1 _TO_ nTotalStudents
should be
FOR I = 1 _TO_ (nTotalStudents-1)

To me using a FOR loop this way looks quite unusual. Why not using:
HReadFirst(dsMyData)
WHILE NOT HOut(dsMyData)
HReadNext(dsMyData)
END

or even shorter
FOR EACH dsMyData
END

von Arie - am 24.02.2015 11:59
Hello Yogi

I appreciate you say it doesn't work using the read loop but putting a for/end loop in place is not the way to try and make it work.
Debug the standard read loop - without any middle part works- because that is the part to fix first


IF HreadFirst(dsMyData)
WHILE NOT HOut(dsMyData)
HReadNext(dsMyData)
END //WHILE NOT HOut(dsMyData)
END //IF HreadFirst(dsMyData)



If that does not work then the problem is in dsMydata

Regards
Al

von Al - am 24.02.2015 12:03
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.