Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I got this tutorial from a text book.

 

Instead of doing it in sql server, I am tring to do it using MS access.

 

After changing every thing, I found that the delete record link button will not work.

 

There is no compiling error of any sort.

 

Please help!! :confused:

 

Thanks

 

 

****************here's the code************************

Sub MyDG_ItemCommand(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs)
       If e.CommandSource.CommandName = "RemoveFromCat" Then
           'Identify the Cell that Contain the CatID
           Dim CatIDCell As TableCell = e.Item.Cells(1)
           Dim CatID As String = CatIDCell.Text

           Dim CatThumbCell As TableCell = e.Item.Cells(4)
           Dim CatThumb As String = CatThumbCell.Text

           Dim CatImageCell As TableCell = e.Item.Cells(3)
           Dim CatImage As String = CatImageCell.Text

           'USe SQL to remove the Cat with CatID = CatIDCell

           dim dbconn,sql, dbcomm,dbread
           dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" _
           & "data source=" & server.mappath("..\TaraStore.mdb"))
           dbconn.Open()
           sql="DELETE FROM Categories WHERE CategoryID =" & CatID

           dbcomm=New OleDbCommand(sql,dbconn)
           dbread=dbcomm.ExecuteNonQuery()
          ' MyDG.DataSource=dbread
           'MyDG.DataBind()
           'dbread.Close()
           dbconn.Close()
           Page.DataBind()

           'Find path to image folder

           Dim strFilePath As String
           strFilePath = System.IO.Path.GetDirectoryName(Server.MapPath("DeletCat.aspx"))

           'Delete Image
           System.IO.File.Delete((strFilePath & "\..\" & "images" & "\" & CatImage))
           'Delete Thumbnail
           System.IO.File.Delete((strFilePath & "\..\" & "images" & "\" & CatThumb))

       Else

       End If
       Page.DataBind()
End Sub

 

**************Here's the html**********************

<body ms_positioning="GridLayout">
   <form id="Form1" method="post" runat="server">
       <asp:DataGrid id="MyDG" style="Z-INDEX: 101; LEFT: 17px; 
        POSITION: absolute; TOP: 80px" runat="server"          
        AutoGenerateColumns="False" DataKeyField="CategoryID" 
        Font-Names=" Verdana" HeaderStyle-     
        BackColor="#aaaadd" Font-Size="8pt" Font-Name="  
        Verdana" CellPadding="3" BorderWidth="1px" BorderColor="Black">
           <HeaderStyle backcolor="LightSteelBlue"></HeaderStyle>
           <Columns>
               <asp:TemplateColumn HeaderText="Select a Task">
                   <ItemTemplate>
                       <asp:LinkButton ID="RemoveButton" CommandName="RemoveFromCat" Text="Delete" ForeColor="Blue" Runat="server" />
                   </ItemTemplate>
               </asp:TemplateColumn>
               <asp:BoundColumn DataField="CategoryID" SortExpression="CategoryID" HeaderText="Category ID"></asp:BoundColumn>
               <asp:BoundColumn DataField="CategoryName" SortExpression="CategoryName" HeaderText="Category Name"></asp:BoundColumn>
               <asp:BoundColumn DataField="CatImage" SortExpression="CatImage" HeaderText="Image"></asp:BoundColumn>
               <asp:BoundColumn DataField="Thumbnail" SortExpression="Thumbnail" HeaderText="Thumbnail"></asp:BoundColumn>
               <asp:BoundColumn DataField="Description" SortExpression="Description" HeaderText="Description"></asp:BoundColumn>
           </Columns>
       </asp:DataGrid>

[edit]Please use

 tags [/vb ] [/edit]
Edited by Robby
Hobbes...
  • Moderators
Posted

What data type is CategoryID in the table? If it's string (text) then try this...

sql="DELETE FROM Categories WHERE CategoryID = '" & CatID & "'"

If it's numeric (integer) then..

sql="DELETE FROM Categories WHERE CategoryID = " & convert.toint32(CatID)

 

ALSO:

You NEED to place the following at the top of each code page...

Option Explicit On

Option Strict On

 

AND:

Declare your variables as types...

these are not: "Dim dbconn,sql, dbcomm,dbread"

it should be something like this...

Dim dbconn as OledbConnection
Dim sql as string
Dim dbcomm as oledbCommand

You should go back to the sample and see how they declared their variables, if the type is SqlConnection then simply replace the Sql with OleDb to get OleDbConnection

Visit...Bassic Software
Posted

Thanks for the reply. :)

 

I have made the changes. However, the problem still exist.

 

Everything runs fine, except for the delete link button that is not responding. It's seems to be missing some on_click event that triggers the "MyDG_ItemCommand" sub.

 

 

I tried to add onClick event into the linkbutton tag but it gave an error that says:

 

Compiler Error Message: BC30408: Method 'Public Sub MyDG_ItemCommand(Sender As Object, e As System.Web.UI.WebControls.DataGridCommandEventArgs)' does not have the same signature as delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'.

 

<asp:LinkButton ID="RemoveButton" CommandName="RemoveFromCat" Text="Delete" 
ForeColor="Blue" onClick= "MyDG_ItemCommand" 
Runat="server" />

 

Any Ideas?? Thanks!

Hobbes...
Posted

I noticed that

 

Sub MyDG_ItemCommand(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs)

 

is not associated w/ any event. Try this:

 

Sub MyDG_ItemCommand(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs) Handles MyDG.ItemCommand

Posted

Thanks for the reply.

 

I tried it and got the following error.

 

Compiler Error Message: BC30506: Handles clause requires a WithEvents variable.

 

 

By the way, I developed it using visual studio using sqlConnection. Now I am using webmatrix to do it in MS access

 

Any ideas??

Hobbes...
Posted

> Compiler Error Message: BC30506: Handles clause requires a WithEvents variable.

 

Search for the declaration of MyDG, probably something like:

 

Protected MyDG As DataGrid

 

Try changing it to:

 

Protected WithEvents MyDG As DataGrid

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...