Tuesday, June 17, 2008

AccessDataSource UpdateCommand Gridview Asp.Net AccessDatabase

Updating Access Database using Asp.Net Gridview - AccessDataSource, UpdateCommand

We can use the following code to update Access Database using Asp.Net Gridview...

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="ID" DataSourceID="AccessDataSource1" AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
</Columns>
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/mReachTV_DB.mdb"
SelectCommand="SELECT [ID], [Country] FROM [TV_Streams]"
UpdateCommand="UPDATE [TV_Streams] SET [Country] = @Country WHERE [ID] = @ID">
</asp:AccessDataSource>

Is it Looking similar to the code you had written??

Thats where the trick is... The number of parameters in Select and Update command should be equal.

No comments: