从不同的表中选择数据 [英] Selecting Data From Different Tables
问题描述
我有两个桌子
ID名称ImageUrl和ID名称CheckInTime CheckOutTime
我有一个ListView,我已经将Name和ImageUrl绑定到了上面,并且运行良好.所以现在,我想从第二个表中选择数据,我想选择CheckInTime和CheckOutTime,但是由于我只选择了第一个表的datasouce来显示ImageUrl中来自数据库的图像.
所以可以建议我通过查询或其他方式执行的操作
我有以下代码
I have two tables
ID Name ImageUrl And ID Name CheckInTime CheckOutTime
I have a listView to which I have bind the the Name and ImageUrl and Working well. So for Now I want to Select data from Second table I want to select CheckInTime and CheckOutTime but as I only have datasouce selected of the first table to display Image from database from ImageUrl.
So what could be suggested for me that could I do It though Query Or some thing else
I have following code
<asp:ListView ID="ListView1" runat="server" DataSourceID="LinqDataSource1" ItemPlaceholderID="ContentID">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tbody runat="server" id="ContentID">
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td width="100px" align="center">
<asp:ImageButton AlternateText="ALi" ID="Imgbtn1" runat="server" ImageUrl='<%# Bind("ImageUrl") %>'
Width="75px" CommandName="Myselect1" CommandArgument='<%# Bind("Name") %>' OnCommand="ImageButton_Command" />
<br />
<%# Eval("Name") %> <br />
</td>
<%-- <%# Eval("CheckInTime")%> - <%# Eval("CheckOutTime")%> --%>
<asp:Label ID="lbl1" runat="server" />
<asp:Label ID="lbl2" runat="server" />
</tr>
</ItemTemplate>
</asp:ListView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Attempt1.DataClasses2DataContext"
EntityTypeName="" OrderBy="ID" Select="new (ID, Name, ImageUrl)" TableName="CheckInCheckOut1s">
</asp:LinqDataSource>
</asp:Content>
在此代码中,我已注释掉他的checkinTime和CheckOutTime,因为它会引发异常
DataBinding:动态类1"不包含CheckInTime的定义
请给我个建议我怎么能摆脱它
问候
Ali
Here In this code I have commented out he checkinTime and CheckOutTime beacuse it arises an Exception
DataBinding:''Dynamic class1'' Does not contain a definition of CheckInTime
Please suugest me How could I get out of it
Regards
Ali
推荐答案
在包含ID名称ImageUrl和CheckInTime CheckOutTime的数据库上创建视图.将该视图用作数据源.
Create a view on the database which contains ID Name ImageUrl And CheckInTime CheckOutTime. Use that view as the datasource.
这篇关于从不同的表中选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!