complete code, with datarows added
this
changes absolutly nothing to my problem, but of course, with the first version
of this code, dt.rows.count will always be 0 !
storing the rowid of each row, then fetching this rowid
just before fetching the next row, solves the problem
the
same code directly with MapBasic works fine, without storing and fetching
RowId
Christophe
-----Message d'origine-----
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Christophe Brabant
Envoyé : mercredi 2 août 2006 09:21
À : [email protected]
Objet : [MI-L] Fetch and table cursor position with Integrated Mapping
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Christophe Brabant
Envoyé : mercredi 2 août 2006 09:21
À : [email protected]
Objet : [MI-L] Fetch and table cursor position with Integrated Mapping
Hi everyone, still a
strange phenomen....
Does the ColumnInfo
statment affect the current cursor position in a table ?
Look at the
following sample, written in VB.NET :
========================================================================================
Public Sub Test(ByVal nom_layer As String)
Dim msg As
String
Dim nom_col As String
Dim dt As DataTable
Dim nb_cols As Short
Dim i As Short
Dim type_col As Short
Dim col_type As System.Type
Dim nb_rows As Integer
Dim j As Integer
Dim log_val As String
Dim rowid As Integer ' **************FOR FIXING BUG***********
Dim jj As Integer
Dim nom_col As String
Dim dt As DataTable
Dim nb_cols As Short
Dim i As Short
Dim type_col As Short
Dim col_type As System.Type
Dim nb_rows As Integer
Dim j As Integer
Dim log_val As String
Dim rowid As Integer ' **************FOR FIXING BUG***********
Dim jj As Integer
Dim nr As
DataRow
Try
msg = "TableInfo(" + nom_layer + "," + TAB_INFO_NROWS.ToString +
")"
jj = mapinfo.eval(msg)
Console.WriteLine("nb rows into " + nom_layer + " : " + jj.ToString)
jj = mapinfo.eval(msg)
Console.WriteLine("nb rows into " + nom_layer + " : " + jj.ToString)
mapinfo.Do("Fetch First From " + nom_layer)
jj = 0
While (mapinfo.Eval("EOT(" + nom_layer + ")") = "F")
mapinfo.Do("Fetch Next From " + nom_layer)
jj += 1
End While
Console.WriteLine("nb rows processed at EOT : " + jj.ToString)
While (mapinfo.Eval("EOT(" + nom_layer + ")") = "F")
mapinfo.Do("Fetch Next From " + nom_layer)
jj += 1
End While
Console.WriteLine("nb rows processed at EOT : " + jj.ToString)
msg = "TableInfo(" + nom_layer + "," + TAB_INFO_NCOLS.ToString +
")"
nb_cols = mapinfo.eval(msg)
nb_cols = mapinfo.eval(msg)
dt = New DataTable(nom_layer)
For i = 1 To
nb_cols
msg = "ColumnInfo(" + nom_layer + "," + """" + "COL" + i.ToString + """" + "," _
+ COL_INFO_NAME.ToString + ")"
nom_col = mapinfo.eval(msg)
msg = "ColumnInfo(" + nom_layer + "," + """" + "COL" + i.ToString + """" + "," _
+ COL_INFO_NAME.ToString + ")"
nom_col = mapinfo.eval(msg)
msg = "ColumnInfo(" + nom_layer + "," + """" + nom_col + """" + ","
_
+ COL_INFO_TYPE.ToString + ")"
type_col = mapinfo.eval(msg)
+ COL_INFO_TYPE.ToString + ")"
type_col = mapinfo.eval(msg)
Select Case
type_col
Case COL_TYPE_CHAR
col_type = System.Type.GetType("System.String")
Case COL_TYPE_DECIMAL
col_type = System.Type.GetType("System.Decimal")
Case COL_TYPE_INTEGER
col_type = System.Type.GetType("System.Int32")
Case COL_TYPE_SMALLINT
col_type = System.Type.GetType("System.Int16")
Case COL_TYPE_DATE
col_type = System.Type.GetType("System.DateTime")
Case COL_TYPE_LOGICAL
col_type = System.Type.GetType("System.Boolean")
Case COL_TYPE_FLOAT
col_type = System.Type.GetType("System.Double")
Case COL_TYPE_GRAPHIC ' special column 'Obj' : nothing to do
GoTo next_column
Case Else ' unknown type
MessageBox.Show("Table " + nom_layer _
+ " : impossible de déterminer le type de la colonne '" + nom_col + "'.", _
"Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Select
Case COL_TYPE_CHAR
col_type = System.Type.GetType("System.String")
Case COL_TYPE_DECIMAL
col_type = System.Type.GetType("System.Decimal")
Case COL_TYPE_INTEGER
col_type = System.Type.GetType("System.Int32")
Case COL_TYPE_SMALLINT
col_type = System.Type.GetType("System.Int16")
Case COL_TYPE_DATE
col_type = System.Type.GetType("System.DateTime")
Case COL_TYPE_LOGICAL
col_type = System.Type.GetType("System.Boolean")
Case COL_TYPE_FLOAT
col_type = System.Type.GetType("System.Double")
Case COL_TYPE_GRAPHIC ' special column 'Obj' : nothing to do
GoTo next_column
Case Else ' unknown type
MessageBox.Show("Table " + nom_layer _
+ " : impossible de déterminer le type de la colonne '" + nom_col + "'.", _
"Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Select
dt.Columns.Add(nom_col, col_type)
next_column:
Next
mapinfo.Do("Fetch First From " + nom_layer)
jj = 0
While (mapinfo.Eval("EOT(" + nom_layer + ")") = "F")
While (mapinfo.Eval("EOT(" + nom_layer + ")") = "F")
nr =
dt.NewRow()
'rowid = mapinfo.eval(nom_layer +
".RowId")
' **************FOR FIXING BUG***********
For i = 1 To
nb_cols
msg = "ColumnInfo(" + nom_layer + "," + """" + "COL" + i.ToString + """" + "," _
+ COL_INFO_TYPE.ToString + ")"
type_col = mapinfo.eval(msg)
msg = "ColumnInfo(" + nom_layer + "," + """" + "COL" + i.ToString + """" + "," _
+ COL_INFO_TYPE.ToString + ")"
type_col = mapinfo.eval(msg)
Select Case
type_col
Case COL_TYPE_CHAR, COL_TYPE_INTEGER, COL_TYPE_SMALLINT, COL_TYPE_DATE
nr(i - 1) = mapinfo.Eval(nom_layer + ".COL" + i.ToString)
Case COL_TYPE_LOGICAL
log_val = mapinfo.Eval(nom_layer + ".COL" + i.ToString)
If log_val = "T" Then
nr(i - 1) = True
Else
nr(i - 1) = False
End If
Case COL_TYPE_DECIMAL
Dim v As String
v = mapinfo.Eval(nom_layer + ".COL" + i.ToString)
nr(i - 1) = CType(v.Replace("."c, ","c), Decimal)
Case COL_TYPE_FLOAT
Dim v As String
v = mapinfo.Eval(nom_layer + ".COL" + i.ToString)
nr(i - 1) = CType(v.Replace("."c, ","c), Double)
End Select
Case COL_TYPE_CHAR, COL_TYPE_INTEGER, COL_TYPE_SMALLINT, COL_TYPE_DATE
nr(i - 1) = mapinfo.Eval(nom_layer + ".COL" + i.ToString)
Case COL_TYPE_LOGICAL
log_val = mapinfo.Eval(nom_layer + ".COL" + i.ToString)
If log_val = "T" Then
nr(i - 1) = True
Else
nr(i - 1) = False
End If
Case COL_TYPE_DECIMAL
Dim v As String
v = mapinfo.Eval(nom_layer + ".COL" + i.ToString)
nr(i - 1) = CType(v.Replace("."c, ","c), Decimal)
Case COL_TYPE_FLOAT
Dim v As String
v = mapinfo.Eval(nom_layer + ".COL" + i.ToString)
nr(i - 1) = CType(v.Replace("."c, ","c), Double)
End Select
Next
dt.Rows.Add(nr)
'mapinfo.do("Fetch Rec " + rowid.ToString + " From " +
nom_layer)
' **************FOR FIXING BUG***********
mapinfo.Do("Fetch Next From " + nom_layer)
jj += 1
End While
End While
dt.AcceptChanges()
Console.WriteLine("table:" + dt.Rows.Count.ToString)
Catch ex As
Exception
Fonctions_diverses.DisplayException(ex)
End Try
End Sub
Fonctions_diverses.DisplayException(ex)
End Try
End Sub
========================================================================================
The output is :
nb rows into Monde7 : 252 ==>
OK
nb rows processed at EOT : 252 ==>
OK
table:133 (for example, or 365, or 411, etc....) ==>
should be 252 !
========================================================================================
ColumnInfo statment, with COL_INFO_TYPE paramater,
seems to affect current cursor position into the Monde7 table (world7 in
english)
sometimes forward, sometimes backward, and by this way,
due to the 'While (mapinfo.Eval("EOT(" + nom_layer + ")") = "F")' _expression_,
the number of lines processed is greater or lower than the true value, who is
252 !
To fix that, I had to add the two lines marked with
**************FOR FIXING BUG*********** in the
code.
Any idea ?
Thank you -
Chris
_______________________________________________ MapInfo-L mailing list [email protected] http://www.directionsmag.com/mailman/listinfo/mapinfo-l
_______________________________________________ MapInfo-L mailing list [email protected] http://www.directionsmag.com/mailman/listinfo/mapinfo-l
