Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2006, 01:41 PM
Authorized User
 
Join Date: Apr 2006
Posts: 31
Thanks: 1
Thanked 0 Times in 0 Posts
Default Deleting problems

I have a administration page with a datagrid showing the DB info. I have a Delete column and an Edit column. I have to click my Delete button twice before it deletes and I'm not sure why.

Code:
Sub dgAdmin_Delete(s As Object, e As DataGridCommandEventArgs)
  Dim LineItemID As Integer = dgAdmin.DataKeys(e.Item.ItemIndex)
  Dim strConn As New SqlConnection("dns")
  Dim strCmd as String

  strCmd = "DELETE FROM Order WHERE LineItemID = @LineItemID" 
  objCmd = New SqlCommand(strCmd, strConn)
  objCmd.Parameters.Add("@LineItemID", sqldbtype.int).value = LineItemID
  strConn.Open()
    Try
      objCmd.ExecuteNonQuery()
    Catch SQLexc as SqlException
      Response.Write("Delete failed. Error details are: " & SQLexc.ToString())
    dgAdmin.EditItemIndex = -1
    End Try
  DataBind()
  strConn.Close()
End Sub
and here is my data grid setup.

Code:
<asp:DataGrid id="dgAdmin" AutoGenerateColumns="false" CellPadding="4" HeaderStyle-VerticalAlign="bottom" DataKeyField="LineItemID" AllowSorting="true" OnSortCommand="dgAdmin_Sort" OnEditCommand="dgAdmin_Edit" OnCancelCommand="dgAdmin_Cancel" OnUpdateCommand="dgAdmin_Update" OnDeleteCommand="dgAdmin_Delete" runat="server">
<ItemStyle Font-Name="Verdana" Font-Size="8pt" />
  <HeaderStyle Font-Name="Verdana" Font-Size="8pt" Font-Bold="true" />
  <AlternatingItemStyle Font-Name="Verdana" Font-Size="8pt" BackColor="#FFF7D5" />
  <Columns>
  <asp:ButtonColumn ButtonType="LinkButton" Text="Del" CommandName="Delete" />        
  <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
  <asp:BoundColumn DataField="Name" HeaderText="Name" sortExpression="Name" ReadOnly="true" ItemStyle-HorizontalAlign="left" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="Extension" HeaderText="Extension" sortExpression="Extension" ReadOnly="true" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="Location" HeaderText="Location" sortExpression="Location" ReadOnly="true" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="OrderTotal" HeaderText="Order Total" sortExpression="OrderTotal" DataFormatString="{0:c}" ReadOnly="true" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="ItemQuantity" HeaderText="Qty" sortExpression="ItemQuantity" ItemStyle-Width="20" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="ItemName" HeaderText="Item" ReadOnly="true" sortExpression="ItemName" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="ItemColor" HeaderText="Color" sortExpression="ItemColor" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="ItemSize" HeaderText="Size" sortExpression="ItemSize" ItemStyle-Width="5" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="LogoOption" HeaderText="Logo Opt" sortExpression="LogoOption" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
  <asp:BoundColumn DataField="LogoPrice" HeaderText="Logo Price" DataFormatString="{0:c}" ReadOnly="true" sortExpression="LogoPrice" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="center" />
</Columns>
</asp:DataGrid>
Any help will be appreciated.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems deleting a record donrafeal Access VBA 0 January 18th, 2007 06:19 PM
Problems In Deleting Record nkrust ASP.NET 1.0 and 1.1 Professional 2 January 12th, 2007 11:52 PM
Deleting Problem vipin.raturi Visual Studio 2005 0 January 4th, 2007 08:15 AM
Deleting from a table stu9820 ASP.NET 1.0 and 1.1 Basics 2 September 23rd, 2003 12:55 PM
Deleting Duplicates ioates SQL Server 2000 5 August 31st, 2003 10:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.