Results 1 to 4 of 4

Thread: Adding new user info to database

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    63

    Unhappy Adding new user info to database

    Hey guys, got a new problem while trying to add a new user into the database.
    After i've submitted all the data i get an error message saying "Conversion failed when converting the varchar value "Aron" to data type int"

    to be honest, im totally stumped as to what this could meen, does it meen its trying to convert string type data to an integer?

    Anyway heres the code im using

    Code:
    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
    
            'Check all required fields are filled in
            If txtName.Text = "" Or txtPassword.Text = "" Or txtPassCheck.Text = "" Or txtPhone.Text = "" Then
                MessageBox.Show("Please fill in all required fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End If
    
    
            'Before proceeding, check that both passwords match
            If txtPassCheck.Text <> txtPassword.Text Then
                MessageBox.Show("Your passwords do not match!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End If
    
    
            'Before proceeding, check that phone number is numeric, if not exit sub
            If IsNumeric(txtPhone.Text) = False Then
                MessageBox.Show("Please enter only numbers!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
                txtPhone.Text = ""
                Exit Sub
            End If
    
            'Declare variables
            Dim sUsername As String = txtName.Text
            Dim sPassword As String = txtPassword.Text
            'Convert text box text to integer value
            Dim iPhone = CInt(txtPhone.Text)
    
            'Open connection
            con.Open()
    
    
            'Create new user
            Try
                CreateLogin.CommandText = ("INSERT INTO Users (UserID, Password, Phone) Values ('" & sUsername & "', '" & sPassword & "', '" & iPhone & "')")
                CreateLogin.ExecuteNonQuery()
                MessageBox.Show("New user created successfully!", "New User", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Catch ex As Exception
                MessageBox.Show("Error occurred: " & ex.Message)
            End Try
    
            'Close Connection
            con.Close()
        End Sub

    Any help would be greatley appreciated!

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Adding new user info to database

    If your "Userid" column is numeric then you are doing what you are suspecting.
    Trying to convert varchar to int.
    Check you database column to see what type you have there.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Adding new user info to database

    It sounds like you must be trying to insert some data into the wrong column. You're inserting a user's name into a column called UserID. Could that be it?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    63

    Re: Adding new user info to database

    ah i get ya, thanks for the help guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width