• DataGridSQLExample

  • “新建项”。

    此时将显示“添加新项”对话框。

  • “ADO.NET 实体数据模型”。

  • “添加”。

    将显示实体数据模型向导。

  • 在“选择您的数据连接”屏幕上,提供与 Northwind数据库的连接。


  • “下一步”。

  • ”表。


    “完成”。

    ”实体显示在实体设计器中。



    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();
            }

    转载自:http://www.wpf123.com/news/?202.html 

  • 相关文章: