WPF TableAdapter没有执行填充?

时间:2012-11-15 16:49:22

标签: c# sql-server wpf visual-studio-2012 wpfdatagrid

我已经配置了TableAdapter Fill来执行返回行的存储过程,并且没有参数。但我似乎无法找到如何获取数据。

 <Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfDatabind3" x:Class="WpfDatabind3.MainWindow"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded_1">
<Window.Resources>
    <local:cbfSQL1DataSet x:Key="cbfSQL1DataSet"/>
    <CollectionViewSource x:Key="spTotalRevByZipViewSource" Source="{Binding spTotalRevByZip,  Source={StaticResource cbfSQL1DataSet}}"/>
</Window.Resources>
<Grid>
    <StackPanel HorizontalAlignment="Left" Height="292" Margin="10,10,0,0"  VerticalAlignment="Top" Width="489" DataContext="{StaticResource spTotalRevByZipViewSource}">
        <DataGrid x:Name="spTotalRevByZipDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" Height="200" ItemsSource="{Binding}" Margin="106,0,-17,0" RowDetailsVisibilityMode="VisibleWhenSelected">
            <DataGrid.Columns>
                <DataGridTextColumn x:Name="custzipColumn" Binding="{Binding custzip}" Header="custzip" Width="SizeToHeader"/>
                <DataGridTextColumn x:Name="subTotalColumn" Binding="{Binding subTotal}"   Header="sub Total" IsReadOnly="True" Width="SizeToHeader"/>
            </DataGrid.Columns>
        </DataGrid>
    </StackPanel>

</Grid>
 </Window>

背后的代码就是这个。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfDatabind3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded_1(object sender, RoutedEventArgs e)
    {

        WpfDatabind3.cbfSQL1DataSet cbfSQL1DataSet = ((WpfDatabind3.cbfSQL1DataSet)(this.FindResource("cbfSQL1DataSet")));
        // TODO: Add code here to load data into the table spTotalRevByZip.
        // This code could not be generated, because the cbfSQL1DataSetspTotalRevByZipTableAdapter.Fill method is missing, or has unrecognized parameters.

        WpfDatabind3.cbfSQL1DataSetTableAdapters.spTotalRevByZipTableAdapter  cbfSQL1DataSetspTotalRevByZipTableAdapter = new  WpfDatabind3.cbfSQL1DataSetTableAdapters.spTotalRevByZipTableAdapter();
        System.Windows.Data.CollectionViewSource spTotalRevByZipViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("spTotalRevByZipViewSource")));
        spTotalRevByZipViewSource.View.MoveCurrentToFirst();
        }
    }
}

我在加载中看到了2个TODO项目,但就像我说我设置了填充,当我在结束时进行预览时,我得到了数据。 // ToDo之后的三行显示在我配置之后。为什么我没有获得数据?

1 个答案:

答案 0 :(得分:0)

@StephanM

我假设,这是因为您没有提到Datagrid的itemsource,您可以尝试使用下面的代码修改 ItemsSource="{StaticResource spTotalRevByZipViewSource}"

道歉,如果我误解了这个问题。

此致