将SQL Server表列值移动到另一个表列

时间:2016-04-21 07:47:10

标签: asp.net sql-server

我正在创建一个ASP.NET,C#应用程序。数据库的结果显示在gridview中。我需要将Name列值移到另一个表中HallID列,而不是41,42,43,44值。 Example1example2

如何将值从HallGroup表格列Name移至HallSeat表格,列HallID

SQL Server创建语句:

Create table Hall
(
    HallID int,
    Name nvarchar(50),
    TicketLimit int
)
GO

Create table HallGroup
(
    HallID int,
    HallGroupID int,
    Name nvarchar(50),
    AZ int
)
GO

Create table HallSeat
(
    HallGroupID int,
    ShowSeatID int,
    Color nvarchar(15),
    Price int,
    SeatRow int,    
    SeatNumber int, 
    IsReserved bit
)

Aspx标记:

<asp:GridView ID="GridView1" runat="server"  
     HorizontalAlign="Center" AllowPaging="True" CellPadding="3" 
     Width="568px" GridLines="Vertical" Visible="False" 
     AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" 
     BorderStyle="None" BorderWidth="1px">       
     <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
     <HeaderStyle BackColor="#121315" Font-Bold="True" ForeColor="White" />
     <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
     <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
     <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
     <SortedAscendingCellStyle BackColor="#F1F1F1" />
     <SortedAscendingHeaderStyle BackColor="#0000A9" />
     <SortedDescendingCellStyle BackColor="#CAC9C9" />
     <SortedDescendingHeaderStyle BackColor="#000065" />  
     <AlternatingRowStyle BackColor="#DCDCDC" />
     <Columns>          
         <asp:TemplateField HeaderText="HALL">
             <EditItemTemplate>
                 <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("HallGroupID") %>'></asp:TextBox>
             </EditItemTemplate>
             <ItemTemplate>
                 <asp:Label ID="Label1" runat="server" Text='<%# Bind("HallGroupID") %>'></asp:Label>
             </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="ID">
             <EditItemTemplate>
                 <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ShowSeatID") %>'></asp:TextBox>
             </EditItemTemplate>
             <ItemTemplate>
                 <asp:Label ID="Label3" runat="server" Text='<%# Bind("ShowSeatID") %>'></asp:Label>
             </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="COLOR">
             <EditItemTemplate>
                 <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Color") %>'></asp:TextBox>
             </EditItemTemplate>
             <ItemTemplate>
                 <asp:Label ID="Label4" runat="server" Text='<%# Bind("Color") %>'></asp:Label>
             </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="PRICE">
             <EditItemTemplate>
                 <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Price") %>'></asp:TextBox>
             </EditItemTemplate>
             <ItemTemplate>
                 <asp:Label ID="Label5" runat="server" Text='<%# Bind("Price") %>'></asp:Label>
             </ItemTemplate>
         </asp:TemplateField>  
         <asp:TemplateField HeaderText="ROW">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("SeatRow") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server" Text='<%# Bind("SeatRow") %>'></asp:Label>
                </ItemTemplate>
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="NUMBER">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("SeatNumber") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label7" runat="server" Text='<%# Bind("SeatNumber") %>'></asp:Label>
                </ItemTemplate>
         </asp:TemplateField>               
         <asp:TemplateField HeaderText="STATUS" SortExpression="Active">
                    <ItemTemplate><%# (Boolean.Parse(Eval("IsReserved").ToString())) ? "RESERVED" : "FREE" %></ItemTemplate>
         </asp:TemplateField>            
         <asp:TemplateField>                  
                <ItemTemplate>                        
                   <asp:Button ID="ButtonReserve" style="background:#2ACC16; border-radius:8px;" runat="server" CommandName="Reserve" HeaderText="BOOK SEAT" Text="Reserve" OnClick="ButtonReserve_Click" />                
             </ItemTemplate>            
         </asp:TemplateField> 
    </Columns>                      
</asp:GridView>

1 个答案:

答案 0 :(得分:4)

HallGroupID表格中加入selectName HallGroup两个表格。

Select HG.Name,HS.ShowSeatID,HS.Color,HS.Price,HS.SeatRow,HS.SeatNumber,HS.IsReserved
FROM HallSeat HS 
JOIN HallGroup HG ON HG.HallGroupID = HS.HallGroupID