Click here to Skip to main content
15,669,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello to everybody! Can you guys help me? I'm using VB.NET and an MS Access database to build an ordering system. In order to remind the user to fill out all fields, I wanted to include a message box, but I'm not sure where to put it. This is my code; all text boxes must have the required information in before they may submit. Please be gentle with me; I'm a beginner. Thankyou.

What I have tried:

ds = New DataSet
adapter = New OleDbDataAdapter("insert into [tblaccts] ([USERNAME],[PASSWORD],[STORE NAME], [IMAGE PATH]) VALUES " &
"('" & usr1.Text & "','" & password1.Text & "','" & storeName.Text & "','" & imagepath.Text & "')", conn)


adapter.Fill(ds, "tblaccts")
usr1.Clear()
password1.Clear()
storeName.Clear()
imagepath.Clear()
PictureBox1.Image = Nothing

GetRecords()
Posted
Updated 31-Oct-22 20:34pm
Comments
Richard Deeming 31-Oct-22 11:21am    
So many problems in such a small sample of code!

Let's start with the most serious: Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.
Richard Deeming 31-Oct-22 11:22am    
Then there's the fact that you're storing your users' passwords insecurely.
Secure Password Authentication Explained Simply[^]
Richard Deeming 31-Oct-22 11:23am    
Then we move on to the fact that you're using a DataAdapter to fill a DataSet, but the query you're executing is an INSERT, which doesn't return any records. You should use an OleDbCommand and call ExecuteNonQuery instead.
Hazel Ann Torno 31-Oct-22 11:35am    
Actually sir, a record from the database is displayed after users click the add button. I simply wanted to add a message box so that I could let them know that all text boxes must be filled out and should not be left empty.
Richard Deeming 31-Oct-22 11:43am    
No. If the columns are required, you need to validate that the user has entered something in all of the textboxes before you try to insert the record in the database.

1 solution

In addition to Richards tips, take a look at:
Validating User Input with VB.NET | CodeGuru[^]

It shows how to validate TextBox fields before submitting them, you should also check if the input text lengths fit in the database fields, which is quite simple to implement.

If you want to give the user a visual clue in the form, you can drag an error provider from the toolbox in the form that will show as a red bullet, see:
ErrorProvider Class (System.Windows.Forms) | Microsoft Learn[^]

And maybe this will make things more clear: Visual Studio 2010 ErrorProvider control in VB.NET[^]
 
Share this answer
 
v4
Comments
Hazel Ann Torno 1-Nov-22 22:25pm    
Hi! Do you have a source like this that combines the use of VB.NET with an error provider?

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