How can it Doesn't Work??!! (delete row from

maranza

New Member
Hi again,<BR><BR>This time I found problems deleting a Row from an MDB database, this is my datagrid (is just the same i been using):<BR><BR><ASP:DataGrid 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></ASP:DataGrid><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 = http://aspmessageboard.com/archive/index.php/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 don't work...<BR><BR>Why?<BR><BR>Any Ideas?<BR><BR>Thanks!!<BR><BR>Salvador Gallego.<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>
 
Back
Top