Visual FoxPro Notes

From PeformIQ Upgrade
Jump to navigation Jump to search


public static void StrToFile(string cExpression, string cFileName)
{ 
  //Check if the sepcified file exists   
  if (System.IO.File.Exists(cFileName) == true) 
  {        
       //If so then Erase the file first as in this case we are overwriting       
       System.IO.File.Delete(cFileName); }      
  //Create the file if it does not exist and open it   
  FileStream oFs = new 
       FileStream(cFileName,FileMode.CreateNew,FileAccess.ReadWrite);       
  //Create a writer for the file   
  StreamWriter oWriter = new StreamWriter(oFs); 
  //Write the contents      
  oWriter.Write(cExpression);      
  oWriter.Flush();   
  oWriter.Close();   
  oFs.Close();
}

Get column names from a dbf table

 

Imports System 
Imports System.Data 
Imports System.Data.OleDb 
Module Module1 
 Sub Main() 
  Try 
   '-- Download and install the latest VFP OLE DB data provider from 
   '-- http://msdn.microsoft.com/vfox­pro/downloads/updates/     
  
Dim conn1 As New OleDbConnection( _
     "Provider=VFPOLEDB.1;Data Source=C:\;") 
   conn1.Open() 

   '-- Lets create some data to work with 
   Dim cmd1 As New OleDbCommand( _ 
    "Create Table TestTable " & 
    "(BlobField W, CharField C(10), Currncy Y, " & _ 
    "DateField D, DTimeField T, Doubl B, Generl G, IntField I, " & _ 
    "LogicBool L, MemoField M, Number N(10), FloatField F(10), " & _ 
    "VarBin Q(10), Varchar V(10))", conn1) 
   cmd1.ExecuteNonQuery()    Dim dt As DataTable = _ 
    conn1.GetOleDbSchemaTable( _
    System.Data.OleDb.OleDbSchemaGuid.Columns, _ 
    New Object() {Nothing, Nothing, "TestTable"})    
 
  For Each dr As System.Data.DataRow In dt.Rows 
    Console.WriteLine( _ 
     dr.Item(0).ToString + ", " + _ 
     dr.Item(1).ToString + ", " + _ 
     dr.Item(2).ToString + ", " + _ 
     dr.Item(3).ToString + ", " + _ 
     dr.Item(4).ToString + ", " + _ 
     dr.Item(5).ToString + ", " + _ 
     dr.Item(6).ToString + ", " + _ 
     dr.Item(7).ToString + ", " + _ 
     dr.Item(8).ToString + ", " + _ 
     dr.Item(9).ToString + ", " + _ 
     dr.Item(10).ToString + ", " + _ 
     dr.Item(11).ToString())  ' etc. 
   Next 
 
   conn1.Close()    Console.ReadLine() ' Read the console and verify what happened     Catch ex As Exception 

   MsgBox(ex.ToString()) 

  End Try 
 End Sub 

End Module