BioloMICS logo
×
BioloMICS menu

Load, modify and save records

 
Many of the examples above can be merged in a single script.
 
Imports System
Imports System.Collections
Imports Biolomics.BioCallback
Imports Biolomics.SharedClasses
 
Public Class MyNewClass
 
     ' This function is called when running this script
     Shared Sub Main()
 
          '     Create an instance of class MyNewClass and call its functions
          Dim c As New MyNewClass
          c.RunQuery()
     End Sub
 
     '     Write sub functions here
     Public Sub RunQuery()
          '     get the current connection
          Dim SqlCo As XConnection = Run.GetCurrentConnection()
          If SqlCo Is Nothing Then
               Return
          End If
 
          '     get a table from its SQL name
          Dim TableDef As XTableDef = SqlCo.GetTableDefByUserNameEng("Yeasts_CBS strains_2")
          If TableDef Is Nothing Then     '     may happen if that table doesn't exist
               Return
          End If
          '     fill in a list of all fields to load
          Dim FieldDefMap As New XFieldDefMap
          Dim FieldDef As XFieldDef = SqlCo.GetFieldByUserNameEng("Summary", TableDef.Key)
          If FieldDef Is Nothing Then     '     that field doesn't exist
               Return
          End If
          FieldDefMap.Add(FieldDef)
 
          '     fill in a request to select records
          Dim Where As XWhere = XWhere.LT(StaticFields.id, 20)     '     In SQL, will expand as "WHERE Id < 20"
 
          '     load the records
          Dim RecordMap As XRecordMap = Run.LoadRecords(TableDef.Key, FieldDefMap, Where)
         
          for Each Record as XRecord in RecordMap
               '     get the Field from the loaded record
               Dim Field As XGField = TryCast(Record.Fields(FieldDef.Key), XGField)
               If Field Is Nothing Then     '     this field doesn't exist or is not a G-Field
                    Return
               End If
               '     change the field here...
 
               '     Save the records without undo
               Record.Save(False)
          Next
     End Sub
 
End Class