Fill a ListView with mssql

select

Member
Licensed User
Longtime User
Hello,

I've a problem with ListView and mssql library.

With:

B4X:
L=a.Query("select COLUMN from TABLE")

I get all values of "COLUMN" in "a" variable.

How I can fill a ListView with the values of "COLUMN"?

Tnx
 

Mahares

Expert
Licensed User
Longtime User
Try this:
B4X:
L=a.Query("select COLUMN from TABLE")  'returns a list
      For i=0 To L.Size-1     'By starting with i=1 you can skip the header as part of the list
         MyListview.AddSingleLine(L.Get(i))
      Next
 
Upvote 0

select

Member
Licensed User
Longtime User
It work's great!

Unfortunately I've a another little problem.

My values ​​are displayed in this way:

[MYVALUE ]


There is a "[" same space and a "]" more in addition to the value.

How I can get only my value? I think that I can use a "for" clycle and the "Regex" function....somebody can help me?

very very tnx
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You can do something like this:
B4X:
Dim strColumn As String
For i=0 To L.Size-1     'By using i=1 you can skip the header as part of the list
     strColumn=L.Get(i)
     strColumn= strColumn.Replace("[","").Replace("]","")
     MyListview.AddSingleLine(strColumn)      
Next
 
Upvote 0

select

Member
Licensed User
Longtime User
Hello I'm back with a new question :)

Now I need to fill a ListView with two line from two column of my DB

I used listview1.addTwoLines and I tried this code:

B4X:
          L=a.Query("select ROW1 from TABLE1")
          For i=1 To L.Size-1   
                strColumn=L.Get(i)
                strColumn= strColumn.Replace("[","").Replace("]","")
      
      
           L1=a2.Query("select ROW2 from TABLE2")
           For i2=1 To L1.Size-1
                strColumn1=L.Get(i2)
                strColumn1= strColumn1.Replace("[[artdes], [","").Replace("]]","") 
          
            ListView1.AddTwoLines (strColumn,strColumn1)
        
        Next
        Next

But didn't work.

Can you help me?

Thank you
 
Upvote 0

eps

Expert
Licensed User
Longtime User
No problem, I only use SQLite DBs... no such issue there.

Are you retrieving information from the same table or a different table? You're not really giving us a lot to go on!
 
Upvote 0

select

Member
Licensed User
Longtime User
Ok, I try to explane better.

This is the code to fill a single line ListView

B4X:
Dim strColumn As String
    For i=0 To L.Size-1   'i=1 - skip header
    strColumn=L.Get(i) ' L is sql List that contains a column of my db. First value of L is passed to a string (strColumn)
    strColumn= strColumn.Replace("[","").Replace("]","") 'I clean the result because We get same "[" with the value
    MyListview.AddSingleLine(strColumn) 'Add line to the ListView     
    Next

Now I need to insert two lines in the ListView.

I used this code:

B4X:
L=a.Query("select ROW1 from TABLE1")
          For i=1 To L.Size-1 
                strColumn=L.Get(i)
                strColumn= strColumn.Replace("[","").Replace("]","") 
     
     
          L1=a2.Query("select ROW2 from TABLE2")
          For i2=1 To L1.Size-1
                strColumn1=L.Get(i2)
                strColumn1= strColumn1.Replace("[[artdes], [","").Replace("]]","")
         
            ListView1.AddTwoLines (strColumn,strColumn1)
       
        Next
        Next

So, we have two Table and I get two value (strColumn and strColumn1). I need do add this two value to my ListView with "AddTwoLines".

The problem is that with my code I fill list view with first value than I get an error.

I think that there is same problem on the 2 "for cycle" in the code.
 
Upvote 0

select

Member
Licensed User
Longtime User
Ok I've changed completely way. I realized that in the previous code was some logical problems.

Now i've made this code:

B4X:
                  ListView1.Clear
                  L=a.Query("select COLUMN1 from TABLE1")
                  For i=1 To L.Size-1
        
                  strColumn=L.Get(i)
                  strColumn= strColumn.Replace("[","").Replace("]","")
    
    
                  strColumn1=a2.Query ("select COLUMN2 from TABLE2 where COLUMN3 = '" & strColumn & "'")
                  strColumn1= strColumn1.Replace("[[], [","").Replace("]]","")
        
                  ListView1.AddTwoLines (strColumn,strColumn1)
    
                 Next

It Works, but I get a "LastException java.lang.NullPointerExcetion" after different number of cycles.

I tried to debug and I get error, one time where "i=27" (for example), next time where "i=127", next where "i=356".....

I don't know why I get casual errors.
 
Upvote 0
Top