Your logic seems to be a bit off. Based on the code you have here I assume that execution never gets into your else statement. Also, this statement is redundant:
If recordbedeleted = False Then
It stands to reason that unless this boolean value is true you do not want to execute the delete statement. I would write that statement something like:
Dim recordbedeleted As Boolean = cmd.ExecuteScalar Is Nothing
If recordbedeleted = True Then
Using cmd2 As New System.Data.SqlClient.SqlCommand("DELETE FROM ATTDivision WHERE DivisionCode = '" & DivisionCode2.Text & " ' ")
cmd2.Connection = sqlcon
Dim strMessage As String
strMessage = "The Division ID number you are attempting to delete has employee records associated to it."
strMessage += " Please try again."
'finishes server processing, returns to client.
strScript += "alert(""" & strMessage & """);"
strScript += "</script>"
If (Not ClientScript.IsStartupScriptRegistered("clientScri pt")) Then
ClientScript.RegisterClientScriptBlock(Me.GetType( ), "clientScript", strScript)
Also, I would change your first SQL Statement to something like:
"SELECT DISTINCT Count(ATTDivision.DivisionCode) " & _
"FROM ATTDivision INNER JOIN " & _
"ATTEmployee ON ATTDivision.DivisionCode = ATTEmployee.DivisionCode " & _
"WHERE (ATTDivision.DivisionCode = '" & DivisionCode2.Text & " ') " & _
"ORDER BY ATTDivision.DivisionDescription")
And then change your boolean equation to something like
Dim recordbedeleted As Boolean = (Convert.ToInt32(cmd.ExecuteScalar) = 0)
Read this if you want to know how to get a correct reply for your question:
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7