1
<Window x:Class="Kvik_Support.KonsulentValg"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="KonsulentValg" Height="150" Width="250"
Background="LightGray" ResizeMode="NoResize">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="10" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition Height="10*" />
<RowDefinition Height="10*" />
<RowDefinition Height="10*" />
<RowDefinition Height="10" />
</Grid.RowDefinitions>
<Label Content="Hvem er du?" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom"/>
<ComboBox Grid.Column="1" Grid.Row="2" Height="25" Name="cmbHvemErDu">
</ComboBox>
<Button Grid.Column="1" Grid.Row="3" Height="25" Width="100" Content="OK" Click="Button_Click" />
</Grid>
</Window>
這是我的窗口XAML代碼,我試圖填補從數據庫項目的組合框...把多個項目的組合框從SQL Server(SSMS)
我想到的是,我可以在項目填寫下面的代碼,但是,使一個XAML解析異常......
public partial class KonsulentValg : Window
{
public KonsulentValg()
{
InitializeComponent();
try
{
SqlConnection lager = new SqlConnection("Data Source=local\\SERVER;Initial Catalog=Kvik-Support;Integrated Security=True");
lager.Open();
SqlCommand thisCommand = lager.CreateCommand();
string command = "SELECT ID, navn FROM Konsulent";
SqlDataAdapter da = new SqlDataAdapter(command, lager);
SqlDataReader thisReader = thisCommand.ExecuteReader();
DataTable datatable = new DataTable();
da.Fill(datatable);
foreach (DataRow row in datatable.Rows)
{
string rows = string.Format("{0}:{1}", row.ItemArray[0], row.ItemArray[1]);
cmbHvemErDu.Items.Add(rows);
}
Console.ReadKey();
thisReader.Close();
lager.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}
,但它沒有可能工作...