Do not use the CTable class directly. Use the preallocated WIDatabase.Table variable instead.

Functions to interact with Tables.

Available functions include:
  • Create - Creates a table in the database
  • Delete - Deletes a table from the database
  • Exists - Checks if a table has already been created in the database
  • GetColumnInfo - Returns information about columns in a table

Namespace: Wiker.WIDatabase
Assembly: 

Syntax

C#
public class CTable
Visual Basic
Public Class CTable
Visual C++
public ref class CTable

Examples

CopyC#
WIDatabase WIDB;
CDatabaseInfo DBInfo;

/* Create CDatabaseInfo object and populate with database login info */
DBInfo = new CDatabaseInfo();
DBInfo.DatabaseType = eDatabaseType.SQL;
DBInfo.Location     = "SqlServer";
DBInfo.DBName       = "TestDatabase";
DBInfo.Username     = "LoginName";
DBInfo.Password     = "LoginPassword";

/* Create new instance of WIDatabase */
WIDB = new WIDatabase(DBInfo);

/*----------------------------------------------------------------------------*/
/* Create a new table in database */

/* Set column names and types to be created in table */
WIDB.Table.Column("ColumnID", eDataType.Int32);
WIDB.Table.Column("Bool",     eDataType.Bool);
WIDB.Table.Column("Byte",     eDataType.Byte);
WIDB.Table.Column("Int16",    eDataType.Int16);
WIDB.Table.Column("Int32",    eDataType.Int32);
WIDB.Table.Column("Int64",    eDataType.Int64);
WIDB.Table.Column("Decimal",  eDataType.Decimal);
WIDB.Table.Column("Double",   eDataType.Double);
WIDB.Table.Column("Float",    eDataType.Float);
WIDB.Table.Column("DateTime", eDataType.DateTime);
WIDB.Table.Column("Char",     eDataType.Char);
WIDB.Table.Column("VarChar",  eDataType.VarChar, 100);
WIDB.Table.Column("Text",     eDataType.Text);
WIDB.Table.Column("Image",    eDataType.Image);
WIDB.Table.Column("Binary",   eDataType.Binary, 100);

/* Set column 'ColumnID' as a Primary Key and Auto Incrementing */
WIDB.Table.PrimaryColumn("ColumnID");
WIDB.Table.AutoIncrementColumn("ColumnID");

/* Create Table in database */
if (!WIDB.Table.Create("tblDataType"))
   {
   MessageBox.Show(string.Format("Failed To Create Table\n{0} - {1}", 
                   WIDB.LastError.ToString(), WIDB.LastErrorMessage));
   }

/*----------------------------------------------------------------------------*/
/* Check if table exists in database */

/* Clear settings to allow variable to be reused without reallocating memory */
WIDB.Table.Clear();

if (!WIDB.Table.Exists("tblDataType"))
   MessageBox.Show("Table tblDataType is not in database");

/*----------------------------------------------------------------------------*/
/* Delete table from database */

WIDB.Table.Clear();

/* Delete table from database */
if (!WIDB.Table.Delete("tblDataType"))
   {
   MessageBox.Show(string.Format("Failed To Create Table\n{0} - {1}", 
                   WIDB.LastError.ToString(), WIDB.LastErrorMessage));
   }

WIDB.Close();

Inheritance Hierarchy

System..::..Object
  Wiker.WIDatabase..::..CTable

See Also