protected override int GetCountCore()
            {
                int             count        = 0;
                OleDbCommand    command      = null;
                OleDbDataReader dataReader   = null;
                string          sqlStatement = "SELECT COUNT(*) FROM " + tableName;

                try
                {
                    command = new OleDbCommand(sqlStatement, connection);
                    ExecutingSqlStatemenOleDbFeatureSourceEventArgs e = new ExecutingSqlStatemenOleDbFeatureSourceEventArgs(command.CommandText, ExecutingSqlStatementType.GetCount);
                    OnExecutingSqlStatement(e);

                    dataReader = command.ExecuteReader();
                    if (dataReader.Read())
                    {
                        count = Convert.ToInt32(dataReader[0], CultureInfo.InvariantCulture);
                    }
                }
                finally
                {
                    if (dataReader != null)
                    {
                        dataReader.Dispose();
                    }
                    if (command != null)
                    {
                        command.Connection.Close();
                        command.Dispose();
                    }
                }
                return(count);
            }
            protected virtual void OnExecutingSqlStatement(ExecutingSqlStatemenOleDbFeatureSourceEventArgs e)
            {
                EventHandler <ExecutingSqlStatemenOleDbFeatureSourceEventArgs> handler = ExecutingSqlStatement;

                if (handler != null)
                {
                    handler(this, e);
                }
            }
            protected override Collection <Feature> GetAllFeaturesCore(IEnumerable <string> returningColumnNames)
            {
                OleDbCommand         command        = null;
                OleDbDataReader      dataReader     = null;
                Collection <Feature> returnFeatures = new Collection <Feature>();

                try
                {
                    command = new OleDbCommand("SELECT " + featureIdColumn + " as TG_ID, " + wkbFieldName + " as TG_Wkb FROM " + tableName, connection);
                    ExecutingSqlStatemenOleDbFeatureSourceEventArgs e = new ExecutingSqlStatemenOleDbFeatureSourceEventArgs(command.CommandText, ExecutingSqlStatementType.GetAllFeatures);
                    OnExecutingSqlStatement(e);

                    command.CommandText = e.SqlStatement;
                    dataReader          = command.ExecuteReader();
                    while (dataReader.Read())
                    {
                        byte[]  wkb     = Convert.FromBase64String(dataReader["TG_Wkb"].ToString());
                        Feature feature = new Feature(wkb, dataReader["TG_ID"].ToString());
                        foreach (string columnName in returningColumnNames)
                        {
                            feature.ColumnValues.Add(columnName, dataReader[columnName].ToString());
                        }
                        returnFeatures.Add(feature);
                    }
                }
                finally
                {
                    if (command != null)
                    {
                        command.Dispose();
                    }
                    if (dataReader != null)
                    {
                        dataReader.Dispose();
                    }
                }
                return(returnFeatures);
            }
        private void OleDbFeature_ExecutingSqlStatement(object sender, ExecutingSqlStatemenOleDbFeatureSourceEventArgs e)
        {
            switch (e.ExecutingSqlStatementType)
            {
            case ExecutingSqlStatementType.GetAllFeatures:
                if (tabControl1.SelectedTab == tabPage2)
                {
                    if (radioButton1.Checked)
                    {
                        e.SqlStatement += " where TG_ID between 1 and 7000";
                    }
                    else if (radioButton2.Checked)
                    {
                        e.SqlStatement += " where TG_ID>7001";
                    }
                }
                else
                {
                    tbxSqlStr.Text = e.SqlStatement;
                    tbxType.Text   = e.ExecutingSqlStatementType.ToString();
                }
                break;

            case ExecutingSqlStatementType.GetCount:
                tbxSqlStr.Text = e.SqlStatement;
                tbxType.Text   = e.ExecutingSqlStatementType.ToString();
                break;

            case ExecutingSqlStatementType.GetFirstGeometryType:
                tbxSqlStr.Text = e.SqlStatement;
                tbxType.Text   = e.ExecutingSqlStatementType.ToString();
                break;

            default:
                break;
            }
        }
            public WellKnownType GetFirstGeometryType()
            {
                OleDbCommand    command      = null;
                OleDbDataReader dataReader   = null;
                WellKnownType   type         = WellKnownType.Invalid;
                string          sqlStatement = string.Format("SELECT TOP 1 {0} FROM {1};", wkbFieldName, tableName);

                try
                {
                    command = new OleDbCommand(sqlStatement, connection);
                    ExecutingSqlStatemenOleDbFeatureSourceEventArgs e = new ExecutingSqlStatemenOleDbFeatureSourceEventArgs(command.CommandText, ExecutingSqlStatementType.GetFirstGeometryType);
                    OnExecutingSqlStatement(e);
                    dataReader = command.ExecuteReader();

                    if (dataReader.Read())
                    {
                        if (dataReader[0] != DBNull.Value)
                        {
                            type = (new Feature((byte[])(Convert.FromBase64String(dataReader[0].ToString())))).GetWellKnownType();
                        }
                    }
                }
                finally
                {
                    if (dataReader != null)
                    {
                        dataReader.Dispose();
                    }
                    if (command != null)
                    {
                        command.Connection.Close();
                        command.Dispose();
                    }
                }
                return(type);
            }