Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Using create As New OleDbCommand("INSERT INTO Loginandregister ([USERNAME],[PASSWORD],[CONFIRMPASSWORD],[GENDER],[LASTNAME],[FIRSTNAME],[PHONENUMBER],[USERTYPE])VALUES(@USERNAME,@PASSWORD,@CONFIRMPASSWORD,@GENDER,@LASTNAME,@FIRSTNAME,@PHONENUMBER,@USERTYPE)", con)
create.Parameters.AddWithValue("@USERNAME", OleDbType.VarChar).Value = LineTextBox4.Text.Trim
create.Parameters.AddWithValue("@PASSWORD", OleDbType.VarChar).Value = LineTextBox3.Text.Trim
create.Parameters.AddWithValue("@LASTNAME", OleDbType.VarChar).Value = LineTextBox2.Text.Trim
create.Parameters.AddWithValue("@FIRSTNAME", OleDbType.VarChar).Value = LineTextBox1.Text.Trim
create.Parameters.AddWithValue("@USERTYPE", OleDbType.VarChar).Value = ComboBox1.Text.Trim
create.Parameters.AddWithValue("@GENDER", OleDbType.VarChar).Value = GunaComboBox1.Text.Trim
create.Parameters.AddWithValue("@CONFIRMPASSWORD", OleDbType.VarChar).Value = LineTextBox5.Text.Trim
create.Parameters.AddWithValue("@PHONENUMBER", OleDbType.Integer).Value = LineTextBox6.Text.Trim
If create.ExecuteNonQuery Then
MessageBox.Show("Account Created Successfuly", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
GunaComboBox1.ResetText()
ComboBox1.ResetText()
LineTextBox1.Clear()
LineTextBox2.Clear()
LineTextBox3.Clear()
LineTextBox4.Clear()
LineTextBox5.Clear()
LineTextBox6.Clear()
End If
End Using

What I have tried:

i run this code and i don't know where is the problem to it.
Posted
Updated 21-Nov-20 20:19pm

1 solution

Probably this bit:
C#
create.Parameters.AddWithValue("@PHONENUMBER", OleDbType.Integer).Value = LineTextBox6.Text.Trim

You are passing text to a integer field, so if the user types the wrong thing - or you got the wrong textbox - it will fail.

But ... there are much worse problems here!

Let's start with the stuff that can cost you serious amounts of money, shall we?
Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

And remember: if this is web based and you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
Individual countries generally have their own laws on data protection which apply to non-web based apps, and apply local fines - but they can be extensive as well!

Secondly, Store your data in appropriate datatypes! Normally, this means using DATETIME for dates instead of strings, and integers where numbers are concerned - but in this case it means not using numeric storage for a "number"!
Numeric storage is for values that you can, will, or might do maths on: counts, indexes, orders. But what is your telephone number times three? What do you get if you add two telephone numbers? What is the sense in comparing two telephone number to find which is "greater"? What - in short - can you usefully do with a telephone number other than dial it? So is it sensible to store it in a numeric field? No.
Additionally, telephone number aren't numeric only data: they often start with "0" and that's an important leading character as it indicates to the exchange that this is a "full STD code" number. Integers don't save leading zeros.
They can also contain non-numeric characters: +44(0)1234 567890x1234 is a valid telephone number indicating country - UK - STD included, but optional when prefixed by "+44", STD code grouped from the "local code", and an extension number. You can;t store that in an integer, and you will get a "datatype mismatch in criteria expression" error if you try...

And do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
 
Share this answer
 
Comments
Richard Deeming 24-Nov-20 2:05am    
Also: don't store the password in plain text twice! (Password and ConfirmPassword)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900