当前位置: 首页>>代码示例>>C#>>正文


C# System.Data.SqlClient.SqlConnection.GetSchema方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlConnection.GetSchema方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.SqlClient.SqlConnection.GetSchema方法的具体用法?C# System.Data.SqlClient.SqlConnection.GetSchema怎么用?C# System.Data.SqlClient.SqlConnection.GetSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlConnection的用法示例。


在下文中一共展示了System.Data.SqlClient.SqlConnection.GetSchema方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: cbSourceDatabase_SelectionChanged

        private void cbSourceDatabase_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string sourceDatabase = this.cbSourceDatabase.SelectedValue as string;
            if (String.IsNullOrEmpty(sourceDatabase) || sourceDatabase == "< Select Database >")
            {
                this.lblSourceTable.Visibility = Visibility.Hidden;
                this.cbSourceTable.Visibility = Visibility.Hidden;

                this.lblSourceTableContent.Visibility = Visibility.Hidden;
                this.dgSourceTableContent.Visibility = Visibility.Hidden;

                this._SourceTables = null;

                return;
            }

            this._SourceTables = new List<string>();
            this._SourceTables.Add("< Select Table >");

            System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
            builder.DataSource = this.txtDbHost.Text;
            builder.InitialCatalog = this.cbSourceDatabase.SelectedValue.ToString();
            builder.UserID = this.txtDbUsername.Text;
            builder.Password = this.txtDbPassword.Password;

            using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(builder.ConnectionString))
            {
                connection.Open();

                System.Data.DataTable schema = connection.GetSchema("Tables");
                foreach (System.Data.DataRow row in schema.Rows)
                {
                    this._SourceTables.Add(row[2].ToString());
                }
            }

            this.cbSourceTable.ItemsSource = this._SourceTables;

            string sourceTable = Functions.GetFromIsolatedStorage(Functions.GetId(this.txtDbHost.Text, sourceDatabase, "SourceTable"));
            if (!String.IsNullOrEmpty(sourceTable))
            {
                this.cbSourceTable.SelectedIndex = this._SourceTables.FindIndex(x => x == sourceTable);
            }

            if (this.cbSourceTable.SelectedIndex < 0 || this.cbSourceTable.Visibility == Visibility.Visible)
            {
                this.cbSourceTable.SelectedIndex = 0;

                this.lblSourceTableContent.Visibility = Visibility.Hidden;
                this.dgSourceTableContent.Visibility = Visibility.Hidden;
            }

            if (this._SourceTables.Count > 1)
            {
                this.lblSourceTable.Visibility = Visibility.Visible;
                this.cbSourceTable.Visibility = Visibility.Visible;

                //save to isolated stoage
                Functions.SaveToIsolatedStorage(Functions.GetId(this.txtDbHost.Text, "SourceDatabase"), sourceDatabase);
            }

            this.ChangeButtonsVisibility();
        }
开发者ID:mvlasenko,项目名称:TridionDesktopTools,代码行数:63,代码来源:MainWindow.xaml.cs


注:本文中的System.Data.SqlClient.SqlConnection.GetSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。