When I try and update using the gridview edit option, all of the
records in the entire Access database
get changed. Is this normal in gridview? Is there a way to change
this behavior? Or should I
be using a different control?
Thanks
Page Code is as follows:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Search Parts By Mfr Bumber</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/
Main.aspx" Style="position: relative; left: 0px; top: -15px;">Goto
Main Page</asp:HyperLink>
<asp:Button ID="Button1" runat="server" Style="left: 249px;
position: relative; top: 73px; z-index: 100;"
Text="Search" />
<asp:Label ID="Label1" runat="server" Style="z-index: 104;
left: 167px; position: absolute;
top: 48px" Text="Enter A Partial Part Number"
Width="230px" Font-Size="14pt"></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" Style="left: 187px;
position: relative;
top: 49px; z-index: 102;"></asp:TextBox><br />
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/
add_data_inventory.aspx"
Style="left: 0px; position: relative; top: -33px"
Width="141px">Goto Add Data Page</asp:HyperLink><br />
</div>
<br />
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
ConflictDetection="CompareAllValues"
DataFile="~/App_Data/Spare_Parts_II_BCPC.mdb"
DeleteCommand="DELETE FROM [Inventory] WHERE [ID1] = ? AND [Mfr] = ?
AND [MFR_PART#] = ? AND [Description] = ? AND [Shelving Unit] = ? AND
[Shelf] = ? AND [Bin#] = ? AND [OnHand] = ?"
InsertCommand="INSERT INTO [Inventory] ([Mfr],
[MFR_PART#], [Description], [Shelving Unit], [Shelf], [Bin#],
[OnHand], [ID1]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [Mfr], [MFR_PART#] AS column1, [Description],
[Shelving Unit] AS Shelving_Unit, [Shelf], [Bin#] AS column2,
[OnHand], [ID1] FROM [Inventory] WHERE ([MFR_PART#] LIKE '%' + ? +
'%')"
UpdateCommand="UPDATE [Inventory] SET [Mfr] = ?,
[MFR_PART#] = ?, [Description] = ?, [Shelving Unit] = ?, [Shelf] = ?,
[Bin#] = ?, [OnHand] = ? AND [Mfr] = ? AND [MFR_PART#] = ? AND
[Description] = ? AND [Shelving Unit] = ? AND [Shelf] = ? AND [Bin#]
= ? AND [OnHand] = ?">
<DeleteParameters>
<asp:Parameter Name="original_ID1" Type="Int32" />
<asp:Parameter Name="original_Mfr" Type="String" />
<asp:Parameter Name="original_column1" Type="String" /
<asp:Parameter Name="original_Description"
Type="String" />
<asp:Parameter Name="original_Shelving_Unit"
Type="String" />
<asp:Parameter Name="original_Shelf" Type="String" />
<asp:Parameter Name="original_column2" Type="String" /
<asp:Parameter Name="original_OnHand" Type="Double" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Mfr" Type="String" />
<asp:Parameter Name="column1" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Shelving_Unit" Type="String" />
<asp:Parameter Name="Shelf" Type="String" />
<asp:Parameter Name="column2" Type="String" />
<asp:Parameter Name="OnHand" Type="Double" />
<asp:Parameter Name="original_ID1" Type="Int32" />
<asp:Parameter Name="original_Mfr" Type="String" />
<asp:Parameter Name="original_column1" Type="String" /
<asp:Parameter Name="original_Description"
Type="String" />
<asp:Parameter Name="original_Shelving_Unit"
Type="String" />
<asp:Parameter Name="original_Shelf" Type="String" />
<asp:Parameter Name="original_column2" Type="String" /
<asp:Parameter Name="original_OnHand" Type="Double" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1"
Name="column1" PropertyName="Text" Type="String" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="Mfr" Type="String" />
<asp:Parameter Name="column1" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Shelving_Unit" Type="String" />
<asp:Parameter Name="Shelf" Type="String" />
<asp:Parameter Name="column2" Type="String" />
<asp:Parameter Name="OnHand" Type="Double" />
<asp:Parameter Name="ID1" Type="Int32" />
</InsertParameters>
</asp:AccessDataSource>
<br />
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="ID1" DataSourceID="AccessDataSource1"
ForeColor="#333333" GridLines="None"
Style="position: relative">
<FooterStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Mfr" HeaderText="Mfr"
SortExpression="Mfr" />
<asp:BoundField DataField="column1"
HeaderText="Mfr_Part_no" SortExpression="column1" />
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="Shelving_Unit"
HeaderText="Shelving_Unit" SortExpression="Shelving_Unit" />
<asp:BoundField DataField="Shelf" HeaderText="Shelf"
SortExpression="Shelf" />
<asp:BoundField DataField="column2"
HeaderText="Bin_No" SortExpression="column2" />
<asp:BoundField DataField="OnHand" HeaderText="OnHand"
SortExpression="OnHand" />
<asp:BoundField DataField="ID1" HeaderText="ID1"
InsertVisible="False" ReadOnly="True"
SortExpression="ID1" />
</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>
</form>
</body>
</html>
ca8msm@aspnetlibrary.com - 29 Aug 2007 13:51 GMT
Your update command doesn't have a WHERE clause in it to specify which
record to update, so yes it would appear to be normal that it is
updating every record.
--
Mark Smith
http://aspnetlibrary.com
Steve - 29 Aug 2007 13:52 GMT
Sounds to me like you need to add a WHERE clause to your update
statement that will limit the update to the row you're editing.
Steve C.
MCSD,MCAD,MCSE,MCP+I,CNE,CNA,CCNA
> When I try and update using the gridview edit option, all of the
> records in the entire Access database
[quoted text clipped - 144 lines]
> </body>
> </html>
Bgreer5050 - 29 Aug 2007 21:26 GMT
I have searched high and low.....how do I write this Where clause so it is
limited to the edit selected row?
> Sounds to me like you need to add a WHERE clause to your update statement
> that will limit the update to the row you're editing.
[quoted text clipped - 150 lines]
>> </body>
>> </html>
Sergio E. - 06 Sep 2007 17:09 GMT
use the fields included in the promary key
if your table has a idtable field, then use where
idfield=selectedrow_idtable field
as a tip, you can use the wizard to create an accessdatasource, select your
mdb, select the table, the fields and there is a button named "advanced", in
the window that is opened, select generate insert, update and delete
statements then ok, then next, then finish. it will generate all you need to
do this works. The only problem you can get is if you haven't defined a
primary key.
greetings
Sergio E.
>I have searched high and low.....how do I write this Where clause so it is
>limited to the edit selected row?
[quoted text clipped - 153 lines]
>>> </body>
>>> </html>