yup, stuck again.. helppp.. i have a simple datagrid, no paging, its has 3 columns, a author, booktitle and price and it loads data depending on if the user has books posted.. what i'm trying to do is allow the user to delete his books if its been sold.. i have a delete button in the datagrid but when i hit it, nothing happens, it doesnt even delete the record from the database.. below is my code if anyone can tell me what i'm doing wrong.. muchos graciousss
Sub dgrdTitles_Delete(Sender As Object, E As DataGridCommandEventArgs)
Dim conbooks As OleDbConnection
Dim isEditing As Boolean = False
If Not isEditing Then
Dim keyValue As String = CStr(dgrdtitles.DataKeys(e.Item.ItemIndex))
conbooks = new OleDbConnection ( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\accounts\jackb\test.mdb")
Dim DeleteCommand As New OleDbCommand("DELETE from online where author='" & keyValue & "'", conbooks)
conbooks.Open()
DeleteCommand.ExecuteNonQuery()
conbooks.Close()
End If
End Sub
<asp:datagrid id="dgrdtitles" runat="server" Width="471px" Height="169px" PageSize="3" AutoGenerateColumns="False"
OnDeleteCommand="DataGrid_Delete">
<HeaderStyle Font-Names="Times New Roman" Font-Bold="True" HorizontalAlign="Center" ForeColor="Maroon"></HeaderStyle>
<PagerStyle BorderWidth="1px" BorderColor="Red" BorderStyle="Dashed" BackColor="MistyRose"></PagerStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="booktitle" HeaderText="Book Title"></asp:BoundColumn>
<asp:BoundColumn DataField="author" HeaderText="Author"></asp:BoundColumn>
<asp:BoundColumn DataField="price" HeaderText="Book Price" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid></P>
Sub dgrdTitles_Delete(Sender As Object, E As DataGridCommandEventArgs)
Dim conbooks As OleDbConnection
Dim isEditing As Boolean = False
If Not isEditing Then
Dim keyValue As String = CStr(dgrdtitles.DataKeys(e.Item.ItemIndex))
conbooks = new OleDbConnection ( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\accounts\jackb\test.mdb")
Dim DeleteCommand As New OleDbCommand("DELETE from online where author='" & keyValue & "'", conbooks)
conbooks.Open()
DeleteCommand.ExecuteNonQuery()
conbooks.Close()
End If
End Sub
<asp:datagrid id="dgrdtitles" runat="server" Width="471px" Height="169px" PageSize="3" AutoGenerateColumns="False"
OnDeleteCommand="DataGrid_Delete">
<HeaderStyle Font-Names="Times New Roman" Font-Bold="True" HorizontalAlign="Center" ForeColor="Maroon"></HeaderStyle>
<PagerStyle BorderWidth="1px" BorderColor="Red" BorderStyle="Dashed" BackColor="MistyRose"></PagerStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="booktitle" HeaderText="Book Title"></asp:BoundColumn>
<asp:BoundColumn DataField="author" HeaderText="Author"></asp:BoundColumn>
<asp:BoundColumn DataField="price" HeaderText="Book Price" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid></P>