在 DataGrid 控件中显示 SQL Server 数据库中的数据
2011-05-17 21:21 观海看云 阅读(3866) 评论(8) 编辑 收藏 举报
XAML:
<Window x:Class="DataGridSQLExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="Window_Loaded"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid Name="DataGridTest"></DataGrid>
</Grid>
</Window>
readonly NorthwindEntities dataEntities = new NorthwindEntities();
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ObjectQuery<Customers> customers = dataEntities.Customers;
var query =
from customer in customers
where customer.City == "London"
orderby customer.CustomerID
select new { customer.CustomerID, customer.CompanyName, customer.ContactName,
customer.ContactTitle };
DataGridTest.ItemsSource = query.ToList();
}
<Window x:Class="DataGridSQLExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="Window_Loaded"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid Name="DataGridTest"></DataGrid>
</Grid>
</Window>
readonly NorthwindEntities dataEntities = new NorthwindEntities();
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ObjectQuery<Customers> customers = dataEntities.Customers;
var query =
from customer in customers
where customer.City == "London"
orderby customer.CustomerID
select new { customer.CustomerID, customer.CompanyName, customer.ContactName,
customer.ContactTitle };
DataGridTest.ItemsSource = query.ToList();
}
作者:观海看云(个人开发历程知识库 - 博客园)
出处:http://www.cnblogs.com/zhangtao/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/zhangtao/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。