这是我的代码。XAML:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding }" Height="200" Name="dataGrid1" Width="200" />
CS :
SqlConnection thisConnection = new SqlConnection(@"Server=(local);Database=Sample_db;Trusted_Connection=Yes;");
thisConnection.Open();
string Get_Data = "SELECT * FROM emp";
SqlCommand cmd = thisConnection.CreateCommand();
cmd.CommandText = Get_Data;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable("emp");
sda.Fill(dt);
// MessageBox.Show(cmd.CommandText);
dataGrid1.ItemsSource = dt.DefaultView;
它在网格上显示线。不是实际数据。请帮助。提前致谢。