本文整理汇总了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();
}