Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
connect.Open()
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM tbluser", connect)
sql = "UPDATE tbluser SET  Username='" & txtusername.Text & "', Password ='" & txtpassword.Text & "' where IDnumber ='" & txtidnumber.Text & "'"
cmd = New OleDb.OleDbCommand(sql, connect)
cmd.ExecuteNonQuery()
connect.Close()
MsgBox("Updated")
Posted
Updated 6-Mar-15 22:18pm
v2
Comments
Richard MacCutchan 7-Mar-15 4:20am    
Your code is at risk of SQL injection, use proper parameterized queries. You should also check the types of your database fields. You should also never store passwords in clear text. I just hope this is not part of a commercial application.

1 solution

Oh dear... :sigh:

Where do I start?
With the SQL Injection? The text based passwords? The redundant code? The outdated functions? Or the implication that this is Web based and you are using message boxes?

They are all problems...and they don't include the problem you have found!

Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

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.[^] (It's in C#, but the pronciples are the same. You should also see here: Commitstrip[^] which might help to explain how such behaviour is considered by the real world.


Why do this:
VB
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM tbluser", connect)
If you are going to immediately do this:
VB
cmd = New OleDb.OleDbCommand(sql, connect)
Why not just create one command?


MsgBox was replaced in 2005 with the more up-to-date MessageBox class and it's Show method. You shouldn't be using the older functions in new code - compatibility only.


VB.NET is web based. Message Boxes are Forms based. If you use a Message Box in a web based system, the client will never see it because it is displayed at the server. It appears to work for development because the two computers are the same physical unit - but in production it fails badly - and convinces your users that your application is rubbish...


Fix that lot, and it's very, very likely that your other problems will just disappear on their own.
Don't fix them, and you are heading for a world of pain...:sigh:
 
Share this answer
 

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