如何通过子表的视图源显示父表的字段。外键。 [英] How to display fields of the parent table in a child table's view source via. foreign key.

查看:64
本文介绍了如何通过子表的视图源显示父表的字段。外键。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS / SQLite / C ++ / xaml

我有两张桌子,书籍和订单:

i am using VS/SQLite/C++/xaml
I have two tables, books and order:

CREATE TABLE books(
id INT PRIMARY KEY AUTOINCREMENT,
title VARCHAR NOT NULL,
pages INT
)

CREATE TABLE order(
id INTEGER PRIMARY KEY AUTOINCREMENT,
booksID INT,
date  NOT NULL,
FOREIGN KEY(booksID) REFERENCES books(id)
)

books :
1    Title1
2    Title2
3    Title3

order :
1     2     2014-3-10
2     3     2014-2-10



在我的VS / C#/ xaml代码中,我准备将MyDataset和viewsource用于两个表:


And in my VS/C#/xaml code, I am ready to use MyDataset and viewsources for two tables:

<Window.Resources>
  <local:SmileDataSet x:Key="MyDataSet"/>
  <CollectionViewSource x:Key="booksViewSource" 

                  Source="{Binding books, Source={StaticResource MyDataSet}}"/>
  <CollectionViewSource x:Key="orderViewSource" 

                  Source="{Binding order, Source={StaticResource MyDataSet}}"/>
</Window.Resources>





我不知道如何显示书中的书名上面的数据网格订单表。

从头开始,我已经尝试过了几种方式,但无法显示它。



以下是我的一些尝试:

(为清晰起见,代码被省略,实际上是伪代码,可能是错误的,对不起!)



I don't know how to display title of books in the above order table of a data grid.
Starting from the scratch, I've been tried several ways, but fails to display it.

The followings are some of my tries :
(codes are omitted for clarity and actually pseudo code, maybe wrong, sorry!)

<DataGrid ItemsSource="{Binding orderViewSource}">
...
  <GridColumn Name="title">
    <GridColumn.CellTemplate>
        <DataTemplate>
           <Textbox text="{Binding ...}"/>
        </DataTemplate>
    </GridColumn.CellTemplate>
  </GridColumn>


or <textbox text="{Binding ...}">



非常感谢任何评论或链接!

谢谢。


Any comments or links are greatly appreciated !
Thanks.

推荐答案

这篇关于如何通过子表的视图源显示父表的字段。外键。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆