Create a new table Index

Namespace: Wiker.WIDatabase
Assembly: 

Syntax

C#
public bool Create(
	string indexName
)
Visual Basic
Public Function Create ( _
	indexName As String _
) As Boolean
Visual C++
public:
bool Create(
	String^ indexName
)

Parameters

indexName
Type: System..::..String
Index name to create

Return Value

bool

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 Index 'IdxFirst' based on column 'FirstName' in table 'Persons' */
WIDB.Index.Table("Persons");
WIDB.Index.Column("FirstName");

if (!WIDB.Index.Create("IdxFirst"))
   {
   MessageBox.Show(string.Format("Failed To Create Index IdxFirst\n{0} - {1}", 
                   WIDB.LastError.ToString(), WIDB.LastErrorMessage));
   return(false);
   }


/* Create unquie Index 'IdxLast' based on column 'LastName' in table 'Persons' */
WIDB.Index.Clear();
WIDB.Index.Table("Persons");
WIDB.Index.Column("LastName");
WIDB.Index.Unquie();

if (!WIDB.Index.Create("IdxLast"))
   {
   MessageBox.Show(string.Format("Failed To Create Index IdxLast\n{0} - {1}", 
                   WIDB.LastError.ToString(), WIDB.LastErrorMessage));
   return(false);
   }


/* Create Index 'IdxNames' based on columns 'FirstName' and 'LastName' in table 'Persons' */
WIDB.Index.Clear();
WIDB.Index.Table("Persons");
WIDB.Index.Column("FirstName");
WIDB.Index.Column("LastName");

if (!WIDB.Index.Create("IdxNames"))
   {
   MessageBox.Show(string.Format("Failed To Create Index IdxNames\n{0} - {1}", 
                   WIDB.LastError.ToString(), WIDB.LastErrorMessage));
   return(false);
   }

WIDB.Close();

See Also