Spludlow Web Header

Text Tables


Introduction

A TextTable is simply a tab delimited text file with the first row containing column names and the second row containing datatypes (datatypes with a star ‘*’ at the end are part of the primary key). Everything after that is the data.

When you are developing you often just want to look at the contents of some DataTable as quickly as possible, you may make many small changes and want to see the data each time.

Text Tables in Code

They are also pretty handy to use in code to define a DataTable as in the code snippet:

DataTable table = Spludlow.Data.TextTable.ReadText(new string[]

{

       "CustId       Name          Address",

       "Int32*       String        String",

       "1000         Fred          56 East Road",

       "1001         Jim           98 Best Drive",

});

You can define an empty table as well as include some data rows, as you would in a lookup table. You can tab everything, so it lines up, making visualization as easy as possible.

Strict vs Slack

Many of the TextTable reading methods include a ‘removeEmptyEntries’ parameter this should be set to true if you are tabbing things out for readability (like in code and configuration files), lines that start with hash “#” are also treated as comments and ignored in this mode. The method called above presumes it will be tabbed out. The downside of using ‘removeEmptyEntries = True’ is that you can’t encode NULL.

Do not use spaces in text tables

TextTables do have their weaknesses; there is no built in way to encode column and row delimiters (tab and newline), they only support a limited number of types (String, Int32, DateTime, etc…), and they don’t perform that well compared to serializing a DataTable out to XML.

 


 
 
 
 
 
 
 
 
 
Spludlow Web Footer