private void dbsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.tablesBox.Items.Clear();
            this.colsView.Rows.Clear();
            this.filterClauseTxtBox.Text = string.Empty;

            TargetDatabaseConfigElement db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(this.dbsComboBox.SelectedIndex);

            statusLbl.Visible = true;

            try
            {
                // Issue a query to get list of all tables
                using (SqlConnection conn = new SqlConnection(db.GetConnectionString()))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(WizardHelper.SELECT_TABLENAMES_QUERY, conn);
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string schema          = reader.GetString(0);
                            string tableName       = reader.GetString(1);
                            string fullName        = string.Format("{0}.{1}", schema, tableName);
                            string quotedTableName = string.Format("[{0}]", tableName);
                            string quotedFullName  = string.Format("[{0}].[{1}]", schema, tableName);

                            if (IsTableNameValid(tableName))
                            {
                                if (schema.Equals("dbo", StringComparison.OrdinalIgnoreCase))
                                {
                                    this.tablesBox.Items.Add(quotedTableName,
                                                             (selectedScope.SyncTables.GetElement(quotedTableName) != null ||
                                                              selectedScope.SyncTables.GetElement(tableName) != null));
                                }
                                else
                                {
                                    this.tablesBox.Items.Add(quotedFullName,
                                                             selectedScope.SyncTables.GetElement(quotedFullName) != null ||
                                                             selectedScope.SyncTables.GetElement(fullName) != null);
                                }
                            }
                        }
                    }
                }
            }
            catch (SqlException exp)
            {
                MessageBox.Show("Error in querying database. " + exp.Message, "Target Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                statusLbl.Visible = false;
            }
        }
        private void tablesBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.filterClauseTxtBox.Text = string.Empty;
            SyncTableConfigElement table = selectedScope.SyncTables.GetElement(this.tablesBox.SelectedItem.ToString());

            if (table != null)
            {
                this.colsView.Rows.Clear();
                this.filterClauseTxtBox.Text = table.FilterClause;

                TargetDatabaseConfigElement db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(this.dbsComboBox.SelectedIndex);

                tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(table.Name, new SqlConnection(db.GetConnectionString()));

                // Display the list of currently selected items
                this.DisplaySyncTableDetails(table);
            }
            else
            {
                colsView.Rows.Clear();
            }
        }
        private void tablesBox_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (tablesBox.SelectedIndex > -1)
            {
                this.colsView.Rows.Clear();
                string tableName = this.tablesBox.SelectedItem.ToString();

                if (e.NewValue == CheckState.Unchecked)
                {
                    // Remove it from the SyncTables collection
                    selectedScope.SyncTables.Remove(tableName);

                    this.filterClauseTxtBox.Text = string.Empty;
                }
                else if (e.NewValue == CheckState.Checked)
                {
                    SyncTableConfigElement table = new SyncTableConfigElement();
                    table.Name = tableName;
                    table.IncludeAllColumns = true;

                    TargetDatabaseConfigElement db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(this.dbsComboBox.SelectedIndex);
                    statusLbl.Visible = true;

                    try
                    {
                        tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(tableName, new SqlConnection(db.GetConnectionString()));

                        // Issue a query to get list of all tables
                        foreach (DbSyncColumnDescription col in tableDesc.Columns)
                        {
                            SyncColumnConfigElement colConfig = new SyncColumnConfigElement()
                            {
                                Name         = col.UnquotedName,
                                IsPrimaryKey = col.IsPrimaryKey,
                                IsNullable   = col.IsNullable,
                                SqlType      = col.Type,
                            };
                            table.SyncColumns.Add(colConfig);
                        }
                        this.DisplaySyncTableDetails(table);
                    }
                    catch (SqlException exp)
                    {
                        MessageBox.Show("Error in querying database. " + exp.Message, "Target Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        statusLbl.Visible = false;
                    }
                    // Add it to the sync table list
                    selectedScope.SyncTables.Add(table);
                }
            }
        }