如何在gridview中更新多个表? [英] how to update multiple table in a gridview ?

查看:57
本文介绍了如何在gridview中更新多个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,我不确定如何编写代码来更新由4个表组成的gridview的行,然后检索它们并将它们的每个新值更新到各自的数据库表?

所以在后端代码中应该如何在rowupdating中调用它

数据库组成的gridview由4个不同的表组成

这意味着该代码在aspx


i have a gridview, i not sure how to code for updating row of a gridview that is make up of the 4 table and retrieve them and update them each new value to it respective database table?

so in the back end code how should call it in rowupdating

the database make up the gridview is make up of 4 different table

which mean this code in aspx


<asp:SqlDataSource ID="SqlDataSource4" runat="server" 

        ConnectionString="<%$ ConnectionStrings:Proj %>" 

        SelectCommand="SELECT image.img, style.styleName, Card.CardName, Card.CardID, Card.price, backViewImg.backViewImg FROM backViewImg INNER JOIN Card ON backViewImg.backViewImgID = Card.backViewImgID INNER JOIN image ON Card.imgID = image.imgID INNER JOIN style ON Card.styleID = style.styleID">
    </asp:SqlDataSource>

推荐答案

ConnectionStrings:Proj%>" span> SelectCommand =" > < /asp:SqlDataSource >
ConnectionStrings:Proj %>" SelectCommand="SELECT image.img, style.styleName, Card.CardName, Card.CardID, Card.price, backViewImg.backViewImg FROM backViewImg INNER JOIN Card ON backViewImg.backViewImgID = Card.backViewImgID INNER JOIN image ON Card.imgID = image.imgID INNER JOIN style ON Card.styleID = style.styleID"> </asp:SqlDataSource>


Herez将示例嵌入到2个表中.您可以将其扩展到4个表.

Herez the sample to embed 2 tables. You can extend it to 4 tables.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" AutoGenerateEditButton="True" DataKeyNames="pk_as_item_id">
<Columns>
<asp:BoundField ReadOnly="true" DataField="pk_as_item_id" HeaderText="ID" SortExpression="pk_as_item_id" />
<asp:BoundField DataField="description" HeaderText="Description" SortExpression="description" />
<asp:TemplateField HeaderText="Location" SortExpression="loca_description" >
<EditItemTemplate>
<asp:DropDownList ID="ddl_location" runat="server" DataSourceID="SqlDataSource2" DataValueField="pk_as_loca_id" DataTextField="loca_description" >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_location" runat="server" Text='<%# Bind("loca_description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%


ConnectionStrings:个人%> " SelectCommand =" UpdateCommand =" < /asp:SqlDataSource > < asp:SqlDataSource ID =" runat 服务器" ConnectionString <%
ConnectionStrings:Personal %>" SelectCommand="SELECT [pk_as_item_id], [description], [fk_as_loca_id], [pk_as_loca_id], [loca_description] FROM [ITEMS], [LOCATIONS] WHERE [fk_as_loca_id] = [pk_as_loca_id]" UpdateCommand="UPDATE [ITEMS] SET [pk_as_item_id] = @pk_as_item_id, [description] = @description, [fk_as_loca_id] = ??????? WHERE [pk_as_item_id] = @pk_as_item_id"> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%


这篇关于如何在gridview中更新多个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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