I am having a problem that dtAsia.rows.count>0 doesn't count at all. All I want to do is tell the user that their username already exists in the game but I'm having a bad time now because for example: I entered a valid username and its success... I entered an invalid username and got the CATCH part of this code.. So if i entered a valid username again. I still got the CATCH part of the code until the end even if I enter valid or invalid username still got the CATCH part. What did I do wrong here? I will really appreciate answers. Thank you

If (dtAsia.Rows.Count > 0) Then ' wont work
            MsgBox("Username: " & Trim(txtUsername.Text) & " is already exist.", MsgBoxStyle.OkOnly, "Message :")
                Call open_conn()
                SqlComm.Connection = conn
                SqlComm.CommandText = "Select * from Personal_Information"
                SqlComm.CommandText = "INSERT INTO Personal_Information(Username) values('" & Trim(txtUsername.Text) & "')
                Call close_conn()
                MessageBox.Show("Account registered successfully!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Call Updater()
            Catch ex As Exception 'Here is the CATCH PART
                MsgBox("error " & Trim(txtUsername.Text) & " is already exist.", MsgBoxStyle.OkOnly, "Message :")
            End Try
        End If

Edited by alfredo11: n/a

5 Years
Discussion Span
Last Post by Netcode

I guess that dtAsia is a dataset you've filled using the username as a criteria, so 0 rows means you've got to insert the user in personal_information.
unfortunately you are not providing what goes on when filling the dtAsia, so my only suggestion would be to step through the code at debug and see where the jump to catch happens and then msgbox yourself the exception to see what goes wrong.

PS: I don't understand why you are first setting the command to a select and then changing it to an insert, but this couldn't be the problem.


oh... I already this figured out.. I removed the TRY statement to see the exact error.. and i got it.. thanks anyways

Votes + Comments
thats the learning process

Dim sqlcon As New SqlClient.SqlConnection(My.Settings.CLSHWSETAConnectionString.ToString)
Dim objCom As New SqlClient.SqlCommand(strquery, sqlcon)


Now you know where the error is, try solving it and if you still encounter further problems, you can surely get your answer here

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.