Android Question How to Bind Sql Data in Grid

Status
Not open for further replies.

junaidahmed

Well-Known Member
Licensed User
Longtime User
Thanks Klaus...

As I have seen the routine " LoadSQLiteDB() ",Is it possible to Load Data from MS SQL to TableView ???
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
I have check "Remote Database Connector" Routine but I am getting error message.Please check blow log error and my code....

Log Error:-
Error occurred on line: 2251 (Table)
java.lang.IllegalArgumentException: Not an array: class anywheresoftware.b4a.objects.collections.Map$MyMap
at java.lang.reflect.Array.notAnArray(Array.java:43)
at java.lang.reflect.Array.get(Array.java:101)
at anywheresoftware.b4a.shell.ArraysUtils.getElement(ArraysUtils.java:76)
at anywheresoftware.b4a.shell.Shell.getArrayElement(Shell.java:566)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:372)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
** Activity (main) Resume **
PackageAdded: package:com.google.android.apps.plus
PackageAdded: package:com.sbi.SBIFreedomPlus

Soure Code :-

Sub LoadGrid(Query As String)
Dim job3 As HttpJob
job3.Initialize("Job3", Me)
'job.PostString(StrURLPath & "RemoteDB/LoadReportName.asp?Month="&Query&"","")
job3.PostString(StrURLPath & "Android/FrmRemoteSQL.aspx",Query)
ProgressDialogShow("Calling KHARIND server...")
End Sub

Sub JobDone (Job As HttpJob)

If Job.Success Then
Dim parser As JSONParser
Dim response As String = Job.GetString
parser.Initialize(response)
Dim rows As List
Dim m As Map
rows = parser.NextArray

'work with result
'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
If Job.JobName = "Job1" Then
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
Log("col1=" & m.Get("Statement")) 'log the values of col1 and col2
LstReports.AddSingleLine(m.Get("Statement"))
Next
else if Job.JobName = "Job2" Then
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
Log("col1=" & m.Get("Query")) 'log the values of col1 and col2
LoadGrid(m.Get("Query"))
Next

else if Job.JobName = "Job3" Then
For i = 0 To rows.Size - 1
Log("Rows #" & i)

m = rows.Get(i)
Log("col1=" & m.Get("Query")) 'log the values of col1 and col2

Next

Table2.Initialize(Me, "Table2")
Table2.AddToActivity(Activity, 10dip, 250dip, 300dip, 200dip)

Table2.LoadRDCResult(m,rows,True)


End If

End If

Job.Release
ProgressDialogHide

End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
First, you should use code tags to insert code:

upload_2017-2-25_9-45-59.png


In what line do you get the error?

I have never used RDC, but from my understanding:
m is a Map with the column names as keys and the indexes as values.
rows is a List, each item is an array of objects.

It seems that you are using for rows a List where each item is a Map !?
Which is not expected by the routine
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
I am getting error on line hightlighted in Bold.Please check below "Table" class and advise how to solve the problem....

Public Sub LoadRDCResult(Columns As Map, Rows As List, AutomaticWidths As Boolean)
cAutomaticWidths = AutomaticWidths
mNumberOfColumns = Columns.Size
innerClearAll(mNumberOfColumns)

Dim Headers(mNumberOfColumns) As String
Dim ColumnWidths(mNumberOfColumns) As Int
Dim HeaderWidths(mNumberOfColumns) As Int
Dim DataWidths(mNumberOfColumns) As Int
Dim col, row As Int
Dim str As String
For col = 0 To mNumberOfColumns - 1
Headers(col) = Columns.GetKeyAt(col)
If AutomaticWidths = False Then
ColumnWidths(col) = 130dip
HeaderWidths(col) = 130dip
DataWidths(col) = 130dip
Else
HeaderWidths(col) = cvs.MeasureStringWidth(Headers(col), Typeface.DEFAULT, cTextSize) + 8dip + cLineWidth
DataWidths(col) = 0

Dim FieldValue As Object
For row = 0 To Rows.Size - 1
Dim Record() As Object = Rows.Get(row)
FieldValue = Record(col)
If GetType(FieldValue) = "java.lang.String" Then
DataWidths(col) = Max(DataWidths(col), cvs.MeasureStringWidth(str, Typeface.DEFAULT, cTextSize) + 8dip + cLineWidth)
End If
Next
ColumnWidths(col) = Max(HeaderWidths(col), DataWidths(col))
End If
Next
SetHeader(Headers)
SetColumnsWidths(ColumnWidths)

For Each Record() As Object In Rows
Dim R(mNumberOfColumns) As String
Dim FieldV As String
For col = 0 To mNumberOfColumns - 1
FieldV = Record(col)
R(col) = FieldV
Next
AddRow(R)
Next
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I repeat again:
First, you should use code tags to insert code:

upload_2017-2-25_9-45-59-png.53186


Have you changed the code you posted in post#9, according to my comments in post#10?
As I already said, I have never used RDC and cannot test it.
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
B4X:
Public Sub LoadRDCResult(Columns As Map, Rows As List, AutomaticWidths As Boolean)
    cAutomaticWidths = AutomaticWidths
    mNumberOfColumns = Columns.Size
    innerClearAll(mNumberOfColumns)

    Dim Headers(mNumberOfColumns) As String
    Dim ColumnWidths(mNumberOfColumns) As Int
    Dim HeaderWidths(mNumberOfColumns) As Int
    Dim DataWidths(mNumberOfColumns) As Int
    Dim col, row As Int
    Dim str As String
    For col = 0 To mNumberOfColumns - 1
        Headers(col) = Columns.GetKeyAt(col)
        If AutomaticWidths = False Then
            ColumnWidths(col) = 130dip
            HeaderWidths(col) = 130dip
            DataWidths(col) = 130dip
        Else
            HeaderWidths(col) = cvs.MeasureStringWidth(Headers(col), Typeface.DEFAULT, cTextSize) + 8dip + cLineWidth
            DataWidths(col) = 0

            Dim FieldValue As Object
            For row = 0 To Rows.Size - 1
                Dim Record() As Object = Rows.Get(row)
                FieldValue = Record(col)
                If GetType(FieldValue) = "java.lang.String" Then
                    DataWidths(col) = Max(DataWidths(col), cvs.MeasureStringWidth(str, Typeface.DEFAULT, cTextSize) + 8dip + cLineWidth)
                End If
            Next
            ColumnWidths(col) = Max(HeaderWidths(col), DataWidths(col))
        End If
    Next
    SetHeader(Headers)
    SetColumnsWidths(ColumnWidths)

    For Each Record() As Object In Rows
        Dim R(mNumberOfColumns) As String
        Dim FieldV As String
        For col = 0 To mNumberOfColumns - 1
            FieldV = Record(col)
            R(col) = FieldV
        Next
        AddRow(R)
    Next
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Please provide me sample code for tableview for below RDC URL

Dim job As HttpJob
Dim StrURLPath as String
Dim Query as String

StrURLPath = "http://103.76.188.138:85/"
Query = "Select DeptName Dept,celltype Sections,empname,total from Mis.Dbo.Vw_StaffSalary Order by DeptName,CellType,EmpCode "

job.Initialize("Job1", Me)
job.PostString(StrURLPath & "Android/FrmRemoteSQL.aspx",Query)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You seem to be very impatient!

As I already said, I have never used RDC.
So I would need to do the same as you could do.
- Look at Erels RDC tutorial understand what the code is doing.
- Perhaps look at other examples.
- Write a small test program to experiment.

This afternoon I am not at home.
 
Upvote 0
Status
Not open for further replies.
Top