1

我已将 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 之后的三行在我配置后出现了。为什么我没有得到数据?

4

1 回答 1

0

@StephanM

I assume, this happens as you have not mentioned the itemsource for the Datagrid, Could you try amend your code with below ItemsSource="{StaticResource spTotalRevByZipViewSource}"

My apologies, if i have misunderstood the question.

Regards

于 2012-11-20T15:54:27.333 回答