Android Question How to get records from database into smtp.body?

ST500

Active Member
Licensed User
Hi,

I use the Net library and would like to get records from a row into smtp.body.
How can I do it?

Thanks a lot.

Martin
 

ST500

Active Member
Licensed User
Sure, I know it. Maybe I‘m unable, but... I allways get only the last record into the smtp.body.
Log shows all records, I don‘t undarstand it, sorry.
 
Upvote 0

ST500

Active Member
Licensed User
That's the code:

B4X:
...
    Dim CursorBaust As Cursor
   Private RowBaust As Int
   Private QueryBaust As String
   Dim BodyRecords As String
   QueryBaust = "SELECT Baustelle From tabBaustelle ORDER BY Baustelle"
   CursorBaust = Starter.SQL1.ExecQuery(QueryBaust)
   For Row = 0 To CursorBaust.RowCount - 1
       CursorBaust.Position = Row
       BodyRecords=CursorBaust.GetString2(0)
       Log(BodyRecords)
       SMTP.Body = BodyRecords & CRLF
   Next
...
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
It's quiet simple actually and I think many of us developers get caught out with this one some or other time.

You see, SMTP.Body is a variable holding information (data) and what you are actually doing with the code you have posted is over writing that variable each time you iterate through the loop. So to fix it, you would need to do something very simple like replacing this line:

SMTP.Body = BodyRecords & CRLF

with:

SMTP.Body = SMTP.Body & CRLF & BodyRecords

Another alternative would be:

B4X:
   For Row = 0 To CursorBaust.RowCount - 1
       CursorBaust.Position = Row
       BodyRecords = BodyRecords & CursorBaust.GetString2(0) & CRLF
       Log(BodyRecords)
   Next
      SMTP.Body = BodyRecords

You see, this statement Log(BodyRecords) writes a line to the log and line feeds it - so it looks correct in the logs as you would expect it and that is what "threw" you off course.

Enjoy !!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…