Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

ASP.NET Gridview - Edit (Update)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bgreer5050@yahoo.com - 29 Aug 2007 13:45 GMT
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 />
       &nbsp;</div>
       &nbsp;<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>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.