Delete Confirmation on a ASP.NET GridView

So I want something a little more than just the Default Delete option that you get with the GridView control. When you click this Delete button, your record just disappears and you’re left for a few moments thinking to yourself, “did I really want to delete that?”.  Well I thought I needed to find a method of being able to prompt the user for a confirmation before actually deleting the record.

After searching the web I came across a version that worked really well and was simple to implement, so I thought I would share it here.

          HeaderText="Record ID"
          ReadOnly="true" />
          HeaderText="Movie Title"
          DataField="MOVIE" />
          SelectText="Select" />
              OnClientClick="return confirm('Are you sure you want to delete this record?');"
              runat="server" />

Technorati Tags: ,,

How to Refresh GridView after Update on DetailsView

When using a master GridView with a details DetailView and an Insert or Update is performed at the DetailsView level the GridView does not refresh with the new values.  This one was bugging me for a while, but I finally found the answer. I knew that is was to do with the DataBind() on the GridView, but where and when did it need to be called.  The answer is to put the DataBind() on the DetailView’s  ItemUpdated  event.

  Private Sub DetailsView1_ItemUpdate(ByVal sender As Object, _
                                      ByVal e As DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
  End Sub

Technorati Tags: ,,

How do you Delete files Older than a given date?

So I got asked if I knew a way of deleting files from a folder that were older than a given date.  I knew this could be done with the Windows OS, bust just how. The Delete command itself is not good enough for the job, so it was time to write a batch file to do the job. I also thought why re-invent the wheel as someone else must have tried this so a quick search on the Internet and I found some information and put it all together. Here is my Batch file, just copy and paste into Notepad.exe and save as DELOLD.bat

   1: @ECHO OFF
   5: echo. >> ~~~FILES_TO_KEEP.TXT~
   6: for /f "tokens=*" %%a IN ('xcopy *.* /d:%1 /L /I null') do if exist %%~nxa echo %%~nxa >> ~~~FILES_TO_KEEP.TXT~
   7: for /f "tokens=*" %%a IN ('xcopy *.* /L /I /EXCLUDE:~~~FILES_TO_KEEP.TXT~ null') do if exist "%%~nxa" del "%%~nxa"
   8: del ~~~FILES_TO_KEEP.TXT~
  10: GOTO END
  12: :SYNTAX
  13: ECHO.
  15: ECHO DELOLD mm-dd-yyyy
  16: ECHO   Where mm-dd-yyyy is the date prior to which you want to delete files.
  17: ECHO.
  18: ECHO EX: "DELOLD 10-17-2008" Deletes files older than October, 17 2008.
  19: GOTO END
  21: :END

You need to enter the date in the given format of mm-dd-yyyy as the XCOPY command needs it this way. Place the batch file in the folder that you need to delete the files from and execute the batch file.

List Data Providers

Here is a small application that I wrote to check your OS for Data Providers currently Installed.  Download and UnZip, and then run the Setup.exe program. This should create a new folder called List Data Providers in your All Programs folder from your Start Bar. Click on the program and it should open up.


Click on the button labelled Providers and it will quickly check what you’ve got configured/installed on your OS. It should come back with a list that looks like this:


ASP.NET 2.0 Oracle Connection

So I wanted to create a connection to my Oracle Database 10g using Visual Studio 2008 in Visual Basic. I was not sure how to go about this to start with as I’ve been teaching myself the .NET framework with some nice books ordered from Amazon.  My problem was that the books would detail nicely how to make connections to MS SQL, but tell you in a small paragraph that you can connect to other database’s such as Oracle or My SQL, just not how to actually do it.

So after a bit of searching on the Web, reading material from Oracle and trying to match up the methods that were used in my books for the MS SQL connection I finally got it working. This is what I did.

First I needed to download the ODP.NET provider from Oracle. Head to the Oracle site and download Oracle 11g ODAC with Oracle Developer Tools for Visual Studio.  Oracle always say that the client software needs to be at the same level or higher than the database, so using 11g Client on a 10g database is fine.  Once downloaded, you’ll need to unzip and run the Setup.exe which will launch the Universal Installer (which does need to be in Administrator mode if running on Vista).

Once installed go to All Programs, Oracle – OraClient11g_home1, Configuration and Migration Tools, and launch Net Configuration Assistant.  Now configure a Listener for your selected protocol (normally TCP and default Port number).  Of course if you have different values then make sure you key in the correct values before saving. Once complete exit from the program.

Now you should be able to start up Visual Studio 2008. Once loaded you create a new ASP.NET Website. Next you’ll need to add a Reference to the Oracle Provider. Click on Website from the menu and then Add Reference. Once the box has loaded, look under the .NET tab for Oracle.DataAccess, highlight and press OK.

Now for some code. First let me tell you about the table within Oracle that I did my testing on.  It’s a simple table called STORE with two columns:

10 Oxford
20 London
30 Leeds
40 Aberdeen
50 Manchester


Now I created a Web Form called readOrcTable.aspx with the following code:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head id="head1" runat="server">
    <title>Show Store Details</title>
    <form id="form1" runat="server">
        Runat="server" />
        Runat="server" />


Next I created a VB Class called OracleSQL.vb with the following code:

Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports Oracle.DataAccess.Client
Imports System.Collections.Generic

Public Class Stores1

    Private Shared ReadOnly _connectionString As String
    Private _Number As String
    Private _Name As String

    Public Property Number() As String
            Return _Number
        End Get
        Set(ByVal value As String)
            _Number = value
        End Set
    End Property

    Public Property Name() As String
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    Public Function GetAll() As List(Of Stores1)
        Dim results As New List(Of Stores1)
        Dim con As New OracleConnection(_connectionString)
        Dim cmd As New OracleCommand("SELECT NO,NAME FROM STORE ORDER BY NO", con)

        Using con
            Dim reader As OracleDataReader = cmd.ExecuteReader()

            While reader.Read()
                Dim NewStore As New Stores1()
                NewStore.Number = CType(reader("NO"), String)
                NewStore.Name = CType(reader("NAME"), String)
            End While

        End Using

        Return results

    End Function

    Shared Sub New()
        _connectionString = "User Id=LoginID;Password=LoginPwd;Data Source=ORACLE;"
    End Sub

End Class

I’ve removed my User Id and Password, which you will have to swap for your own.  And that is all that there is too it.

To Create a iPhone Ringtone from your Music Collection

The one thing that I found when I got my iPhone was that you could not use loaded music as your Ringtones. So, the first thing I did was to look around the internet for a method or means of doing this. Of course I find that people have written applications that will do the job for you but are going to charge you to download their software and use it. So I thought, lets go back and look at iTunes and see what can be done. After a little playing about I found that I could create a iPhone ringtone from any non DRM track in my music collection. Here is how to go about it:

  1. Open iTunes (if you don’t have it get it from ) and select and music track which does not had DRM (Digital Rights Management).
  2. Right Mouse click and select Get Info.
  3. Select the Options tab across the stop.
  4. On this screen you need to select the start and end time for the Ringtone, remember it can only be a maximum of 30 seconds. If you wish to take it from the start them just tick the end box and enter 30 in the second’s box.
    Now press OK.
  5. Right Mouse click the Song Entry and select Create Version from the menu. You will now see a new entry for the song you selected and it’s time length should match what you typed in, 30 seconds?!?
  6. Right Mouse click on the Original Song entry and click on Get Info. Select Options from the Tabs. Un-tick the Start and End times for your song (else next time you sync you will get a short song).
  7. Browse to where iTunes stores its Music normally: C:\Users\Matt\Music\iTunes Media (just browse to the name of your login name) and create a New Folder called Ringtones (once created you will not need to do this step again).
  8. Look in the folder C:\Users\Matt\Music\iTunes Media\Music\<artist>\<album> and Cut the newly created file and Paste it into C:\Users\Matt\Music\iTunes Media\Ringtones your new Folder where you will keep all your new Ringtones.
  9. This file will have a track name like <track name>.m4a Windows recognises the file type by the extension so .M4A is iTunes Music file and .M4R is iTunes Ringtone. So you now need to Rename the file to <track name>.m4r
  10. Back in iTunes delete the 30 second entry of the new duplicate track from iTunes.
  11. Back to the Folder where you copied the track to, double click on the file and it will be added to iTunes under the Ringtone section on the left hand menu.
  12. All you need to do now is connect your iPhone and Sync the Ringtones.
Technorati Tags: ,,