|
-
Feb 4th, 2011, 04:53 PM
#1
Thread Starter
Member
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!
-
Feb 4th, 2011, 08:30 PM
#2
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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Feb 4th, 2011, 08:37 PM
#3
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?
-
Feb 5th, 2011, 09:50 AM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|