Home > SQL Development > Strange error deleting a record from mdb table, help.

Strange error deleting a record from mdb table, help.



<i><b>Originally posted by : Salvador Gallego (salvito@hispavista.com)</b></i><br />Hi all, <br /><br />I found problems deleting a Row from an MDB database, this is my datagrid (is just the same i been using): <br /><br /><ASPataGrid id="DBAddDataGrid" runat="server" <br /> Width="100%" <br /> BackColor="white" <br /> BorderColor="black" <br /> ShowFooter="false" <br /> CellPadding=3 <br /> CellSpacing="0" <br /> Font-Name="Verdana" <br /> Font-Size="8pt" <br /> Headerstyle-BackColor="lightblue" <br /> Headerstyle-Font-Size="10pt" <br /> Headerstyle-Font-Style="bold" <br /> OnDeleteCommand="DBAddDataGrid_Delete" <br />> <br /> <Columns> <br /> <asp:ButtonColumn <br /> HeaderText="Delete Item" <br /> ButtonType="PushButton" <br /> Text="Trash It!" <br /> CommandName="Delete" /> ---> "CommandName" added <br /> </Columns> <br /></ASPataGrid> <br /><br />------------------ <br /><br />And here's the procedure which doesn't work to delete a row: <br /><br />------------------ <br /><br /> Sub DBAddDataGrid_Delete(Sender As Object, E As DataGridCommandEventArgs) <br />'<!-- Dim objConnection Declared on top --> <br />'<!-- Dim objCommand Declared on top --> <br /> Dim DeleteCmd As String = "DELETE from tbdownloads where IdF = @Id" <br /> <br /> objCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11)) <br /> objCommand.Parameters("@Id").Value = DBAddDataGrid.DataKeys(CInt(E.Item.ItemIndex)) <br /> objCommand = New OleDbCommand (DeleteCmd, objConnection) <br /><br /> objConnection.Open() <br /> objCommand.ExecuteNonQuery <br /> objConnection.Close() <br /> ShowDataGrid() <br /> End Sub <br /><br />------------------ <br /><br /><br />The Idea is that I render a field called Id which I use in the Sql query to compare with my autonumber field called IdF and then if it's the same, delete that row... <br /><br />But, of course, it doesn't work, the error I get is:<br /><br />----<br />Object reference not set to an instance of an object. <br />Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br /><br />Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.<br /><br />Source Error: <br /><br /><br />Line 24: Dim DeleteCmd As String = "DELETE from tbdownloads where IdF = @Id"<br />Line 25: <br />Line 26: objCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11)) <br />Line 27: objCommand.Parameters("@Id").Value = DBAddDataGrid.DataKeys(CInt(E.Item.ItemIndex))<br />Line 28: objCommand = New OleDbCommand (DeleteCmd, objConnection) <br />---- <br /><br />Why? <br /><br />Any Ideas? <br /><br />Thanks!! <br /><br />Salvador Gallego. <br /><br />

    
Guest


So objCommand and the othe connection stuff has been created with CreatObject somewhere else?

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved