I have a select case to chose what is true. THe problem is if the information isn't in the database, it automatically skips to the else however i dont kno why.

I have a function that returns an errmessage once it is returned then i use the select case.

the code for the function is:

Function SQLCHECKUSER() As Object
        Dim query1 As String = "SELECT [User_Name] FROM [FDXUSER] WHERE ([User_Name] ='" & User_Name.Text & "')"
        Dim query2 As String = "SELECT [employee_number] FROM [FDXUSER] WHERE ([employee_number] ='" & empnumber.Text & "')"
        Dim query3 As String = "SELECT [Email] FROM [FDXUSER] WHERE ([Email] ='" & email_address.Text & "')"
        Dim sqlcommand As New OleDbCommand(query1, Sqlconnection)
        Dim sqlcommand2 As New OleDbCommand(query2, Sqlconnection)
        Dim sqlcommand3 As New OleDbCommand(query3, Sqlconnection)
        Dim obj As Object
        Dim obj2 As Object
        Dim obj3 As Object

        obj = sqlcommand.ExecuteScalar()
        obj2 = sqlcommand2.ExecuteScalar()
        obj3 = sqlcommand3.ExecuteScalar()
       
        If obj & obj2 & obj3 Is Nothing Then
            Return errmessage = "SUCCESS"
        Else
            If obj Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "USER"
            End If
            If obj2 Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "EMPLOYEE"
            End If
            If obj3 Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "EMAIL"
            End If

        End If

    End Function

Then the select case is:

SQLCHECKUSER()
                Select Case errmessage
                    Case errmessage = "EMPLOYEE"
                        pageerrorlbl.Text = "Sorry! The Employeed Number You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                        Exit Sub
                    Case errmessage = "USER"
                        pageerrorlbl.Text = "Sorry! The User Name You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                        Exit Sub
                    Case errmessage = "EMAIL"
                        pageerrorlbl.Text = "Sorry! The Email Address You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                        Exit Sub
                    Case errmessage = "INSERT" Or errmessage = "SUCCESS"
                        Sqlcommand.CommandText = sqlinsert
                        Sqlcommand.Connection = Sqlconnection
                        Sqlcommand.ExecuteNonQuery()
                        Response.Redirect("confirmreg.aspx")
                        Exit Select
                    Case errmessage = "FAILED"
                        pageerrorlbl.Text = "Sorry! Something is wrong. Please contact the administrator"
                        Exit Select
                    Case Else
                        pageerrorlbl.Text() = "SKIPPED EVERYTHING"
                        Exit Select
                End Select

for some reason it skips the entire select case command and goes straight for else.

I'm not familiar with ASP but in VB, and from what I've seen of ASP, your Case statements should not include
errmessage =
but should just be
Case "EMPLOYEE"
...
Case "USER"
...etc, etc...
- that's my hunch, anyway...
best of luck -
gh

hmm... this didn't work either.

now i get

Conversion from string "INSt" to type 'Long' is not valid.

in the top left as catch exception

It seems that the error is not related to Select Case statement.

I have checked your code after removing 'errmessage = ' from your Select Case.. statements. It is working without throwing any error.

See this below code

Select Case errmessage
            Case "EMPLOYEE"
                pageerrorlbl.Text = "Sorry! The Employeed Number You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                Exit Sub
            Case "USER"
                pageerrorlbl.Text = "Sorry! The User Name You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                Exit Sub
            Case "EMAIL"
                pageerrorlbl.Text = "Sorry! The Email Address You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                Exit Sub
            Case "INSERT" Or "SUCCESS"
                Sqlcommand.CommandText = sqlinsert
                Sqlcommand.Connection = Sqlconnection
                Sqlcommand.ExecuteNonQuery()
                Response.Redirect("confirmreg.aspx")
                Exit Select
            Case "FAILED"
                pageerrorlbl.Text = "Sorry! Something is wrong. Please contact the administrator"
                Exit Select
            Case Else
                pageerrorlbl.Text() = "SKIPPED EVERYTHING"
                Exit Select
        End Select

Hmm for some reason this didnt' work. it still skipped to SKIPPED EVERYTHING.

My Entire code is:

'code
Imports System.Web.Mail
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbDataReader



'end code
Partial Class _Default
    Inherits System.Web.UI.Page
    'set the variables needed
    Dim SqlConnectionString As String
    Dim Sqlconnection As New OleDbConnection
    Dim Sqlcommand As New OleDbCommand(sqlinsert, Sqlconnection)
    Dim SqlData As OleDbDataReader
    Dim sqlinsert As String
    Dim number As String = "3"
    Dim errmessage As String

    'Function used to open the Database
    Function sqlDBconnection() As Object
        'creating the connection string
        SqlConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Users\Tyler\My Documents\FDXNEWS\FDXDB3.mdb';User ID=Admin;Password=;"

        'set the connection string into the SQL connection
        Sqlconnection.ConnectionString = SqlConnectionString
        'open the connection
        Sqlconnection.Open()
        Return 0
    End Function

    'Function used to close the database
    Function SqlDBConnectionClose() As Object
        'close the connection
        Sqlconnection.Close()
        Return 0
    End Function
    Function Verification() As Object

        If first_name.Text.Length = 0 Then
            frstnamelbl.Text = "Please Enter your First Name"
            errmessage = "Failed"
        Else
            frstnamelbl.Text = ""

        End If

        If last_name.Text.Length = 0 Then
            lstnamelbl.Text = "Please enter your Last Name"
            errmessage = "Failed"

        Else
            lstnamelbl.Text = ""
        End If

        If email_address.Text.Length = 0 Then
            emaillbl.Text = "Please Enter a valid email address"
            errmessage = "Failed"
        Else
            emaillbl.Text = ""
        End If

        If Stationident.Text = "Please Choose One" Then
            stationidlbl.Text = "Please Select a Station ID."
            errmessage = "Failed"
        Else
            stationidlbl.Text = ""
        End If

        If password1.Text <> password2.Text Or password1.Text.Length < 6 Or password2.Text.Length < 6 Then
            passlbl.Text = "Please Enter a valid password. Must be more than 6 characters but less than 8."
            errmessage = "Failed"

        Else
            passlbl.Text = ""
        End If

        If empnumber.Text.Length = 0 Then
            empnumberlbl.Text = "Please Enter a valid Employee Number"
            errmessage = "Failed"
        Else
            empnumberlbl.Text = ""
        End If

        Return errmessage

    End Function
    Function SQLCHECKUSER() As Object
        Dim query1 As String = "SELECT [User_Name] FROM [FDXUSER] WHERE ([User_Name] ='" & User_Name.Text & "')"
        Dim query2 As String = "SELECT [employee_number] FROM [FDXUSER] WHERE ([employee_number] ='" & empnumber.Text & "')"
        Dim query3 As String = "SELECT [Email] FROM [FDXUSER] WHERE ([Email] ='" & email_address.Text & "')"
        Dim sqlcommand As New OleDbCommand(query1, Sqlconnection)
        Dim sqlcommand2 As New OleDbCommand(query2, Sqlconnection)
        Dim sqlcommand3 As New OleDbCommand(query3, Sqlconnection)
        Dim obj As Object
        Dim obj2 As Object
        Dim obj3 As Object

        obj = sqlcommand.ExecuteScalar()
        obj2 = sqlcommand2.ExecuteScalar()
        obj3 = sqlcommand3.ExecuteScalar()
       
        If obj Or obj2 Or obj3 Is Nothing Then
            Return errmessage = "SUCCESS"
        Else
            If obj Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "USER"
            End If
            If obj2 Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "EMPLOYEE"
            End If
            If obj3 Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "EMAIL"
            End If

        End If

    End Function
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Verification()
        If errmessage = "Failed" Then
            pageerrorlbl.Text = "Please correct the following red items before you continue!"
            Exit Sub

        Else

            Try
                sqlDBconnection()
            Catch ex As Exception
                Response.Write(ex.Message)
                Exit Sub
            End Try

            sqlinsert = "INSERT INTO FDXUSER(employee_number, First_Name, Last_Name, Email, Station_ID, User_Name, [Password], Security_Level) VALUES ('" & empnumber.[Text] & "','" & first_name.[Text] & "','" & last_name.[Text] & "','" & email_address.[Text] & "','" & Stationident.Text & "','" & User_Name.[Text] & "','" & password1.[Text] & "','3')"
            Try
                SQLCHECKUSER()
                Select Case errmessage
                    Case "EMPLOYEE"
                        pageerrorlbl.Text = "Sorry! The Employeed Number You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                        Exit Sub
                    Case "USER"
                        pageerrorlbl.Text = "Sorry! The User Name You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                        Exit Sub
                    Case "EMAIL"
                        pageerrorlbl.Text = "Sorry! The Email Address You have entered already exist. Please Contact the Web Admin if you think this is a mistake."
                        Exit Sub
                    Case "INSERT" Or "SUCCESS"
                        Sqlcommand.CommandText = sqlinsert
                        Sqlcommand.Connection = Sqlconnection
                        Sqlcommand.ExecuteNonQuery()
                        Response.Redirect("confirmreg.aspx")
                        Exit Select
                    Case "FAILED"
                        pageerrorlbl.Text = "Sorry! Something is wrong. Please contact the administrator"
                        Exit Select
                    Case Else
                        pageerrorlbl.Text() = "SKIPPED EVERYTHING"
                        Exit Select
                End Select

              

            Catch ex As Exception
                Response.Write(ex.Message)
                Exit Sub
            End Try

            Try
                SqlDBConnectionClose()

            Catch ex As Exception
                Response.Write(ex.Message)
                Exit Sub
            End Try
        End If

    End Sub
End Class

Put a break point in the following line.

Select Case errmessage

And see the value of the variable 'errmessage'.

Ignore this

Hmm for some reason i commented out all the Select case info and then told it to display the errmessage under pageerrlbl.text, however this didn't work either.

I got this err message:

Conversion from string "ctyokley" to type 'Long' is not valid.

I am unaware of what this means. Could you please tell me?

In which line this error was thrown? Any line is specified in the Stack Trace of the Exception?

The issue is with this line Case "INSERT" Or "SUCCESS". Rewrite this line as Case "INSERT", "SUCCESS". This should work.

So i did what Lorie said, however it still gave teh same error with the ctyokley string. it doesn't give a line tho. not sure what that is.

Ok so i have eliminated the problem to the function of the sqlcheckuser. For some reason, when i run the following function:

Function SQLCHECKUSER() As Object
        Dim query1 As String = "SELECT [User_Name] FROM [FDXUSER] WHERE ([User_Name] ='" & User_Name.Text & "')"
        Dim query2 As String = "SELECT [employee_number] FROM [FDXUSER] WHERE ([employee_number] ='" & empnumber.Text & "')"
        Dim query3 As String = "SELECT [Email] FROM [FDXUSER] WHERE ([Email] ='" & email_address.Text & "')"
        Dim sqlcommand As New OleDbCommand(query1, Sqlconnection)
        Dim sqlcommand2 As New OleDbCommand(query2, Sqlconnection)
        Dim sqlcommand3 As New OleDbCommand(query3, Sqlconnection)
        Dim obj As Object
        Dim obj2 As Object
        Dim obj3 As Object

        obj = sqlcommand.ExecuteScalar()
        obj2 = sqlcommand2.ExecuteScalar()
        obj3 = sqlcommand3.ExecuteScalar()
       
        If obj Or obj2 Or obj3 Is Nothing Then
            Return errmessage = "SUCCESS"
        Else
            If obj Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "USER"
            End If
            If obj2 Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "EMPLOYEE"
            End If
            If obj3 Is Nothing Then
                Return errmessage = "INSERT"
            Else
                Return errmessage = "EMAIL"
            End If

        End If

    End Function

It comes back and says error.... becuase i run a TRY END TRY with a catch ex as message. and the error says "Conversion from string "ctyokley" to type 'Long' is not valid. "

Somewhere withing that function is my error, but i'm not sure what. Any clue? I tried the textbox.text.tostring and that didnt' work... now i dont kno any other suggestions.

Ok so the Case problem has been solved. Now i am openin up another thread to help out with that function problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.