兰保明

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 1 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
2 AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE"
3 BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="name"
4 DataSourceID="AccessDataSource1" ForeColor="Black" GridLines="Vertical"
5 Width="722px">
6 <FooterStyle BackColor="#CCCC99" />
7 <RowStyle BackColor="#F7F7DE" />
8 <Columns>
9 <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
10 ShowSelectButton="True" />
11 <asp:BoundField DataField="name" HeaderText="name" ReadOnly="True"
12 SortExpression="name" />
13 <asp:BoundField DataField="key" HeaderText="key" SortExpression="key" />
14 </Columns>
15 <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
16 <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
17 <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
18 <AlternatingRowStyle BackColor="White" />
19 </asp:GridView>
20 <asp:AccessDataSource ID="AccessDataSource1" runat="server"
21 DataFile="~/App_Data/studydata.mdb"
22 DeleteCommand="DELETE FROM [user] WHERE [name] = ?"
23 InsertCommand="INSERT INTO [user] ([name], [key]) VALUES (?, ?)"
24 SelectCommand="SELECT * FROM [user]"
25 UpdateCommand="UPDATE [user] SET [key] = ? WHERE [name] = ?">
26 <DeleteParameters>
27 <asp:Parameter Name="name" Type="String" />
28 </DeleteParameters>
29 <UpdateParameters>
30 <asp:Parameter Name="key" Type="String" />
31 <asp:Parameter Name="name" Type="String" />
32 </UpdateParameters>
33 <InsertParameters>
34 <%--<asp:Parameter Name="name" Type="String" />
35 <asp:Parameter Name="key" Type="String" />--%>
36 <asp:FormParameter Name="name" FormField="TextBox1" />
37 <asp:FormParameter Name="key" FormField="TextBox2" />
38 </InsertParameters>
39 </asp:AccessDataSource>
40 <asp:DropDownList ID="DropDownList1" runat="server"
41 DataSourceID="AccessDataSource1" DataTextField="name" DataValueField="name"
42 Width="119px">
43 </asp:DropDownList>
44 <asp:DropDownList ID="DropDownList2" runat="server"
45 DataSourceID="AccessDataSource1" DataTextField="key" DataValueField="key"
46 Width="140px">
47 </asp:DropDownList>
48 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
49 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
50 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

后台只需要一句代码

 protected void Button1_Click(object sender, EventArgs e)
    {
       // AccessDataSource1.InsertParameters["name"]. = TextBox1.Text;
       // AccessDataSource1.InsertParameters["key"].DefaultValue = TextBox2.Text;
        AccessDataSource1.Insert();
    }

具体操作步骤如下:

选择高级出现下面的界面,选生成insert update delete 语句即可

 

posted on 2011-09-08 14:50  兰保明  阅读(1141)  评论(0编辑  收藏  举报