Try
Dim CmdEP As New SqlCommand
Dim CmdEP2 As New SqlCommand
CnSql.Open()
With CmdEP
.Connection = CnSql
.CommandType = CommandType.Text
.CommandText = " DELETE FROM Productos " & _
" FROM Categorias INNER JOIN " & _
" Productos ON Categorias.Id_Categoria = Productos.Id_Categoria " & _
" WHERE Categorias.Id_Categoria = " & miIdC
.ExecuteNonQuery()
End With
CnSql.Close()
CnSql.Open()
With CmdEP2
.Connection = CnSql
.CommandType = CommandType.Text
.CommandText = " DELETE FROM Categorias " & _
" WHERE Categorias.Id_Categoria = " & miIdC
.ExecuteNonQuery()
End With
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Critical, "SISTEMA MACHADO")
Finally
If Not CnSql Is Nothing Then
If CnSql.State = ConnectionState.Open Then
CnSql.Close()
End If
End If
End Try