Skip to content
Advertisement

New to SQL and having issues with Sytnax (VB.NET)

I am fairly new to SQL and databases in general (in an intro class in college right now) and I have run into a little snag. I am building a paid time off tracker for people in my department (they are like children and can’t keep track of their own things with the tools we already have). I currently have working code that when the person inputs the total PTO hours it adds the appropriate record to my database, but when trying to edit that record I keep getting a syntax error.

I am trying to reduce/update the database entry based off what is calculated into two labels that makes it easier to read in the application. I have reviewed multiple YouTube videos and threads that still haven’t helped (hence why I am here). Below is the code I currently have inside the click event for the “Submit PTO” button:

Any help on this would be greatly appreciated. It is probably something stupid easy, but I apparently can’t find it to save my life.

Advertisement

Answer

Don’t try to do arithmetic with Strings. Text properties contain Strings.

You change the value of Protected after you update the database. It is silly to update that field if you don’t change it.

I am going to assume that you want to update the record of a particular employee. I have added a text box for an employee ID that is an Integer. I also guessed that there is a field in the database that has for the Id. I called it EmployeeID.

Connections and Commands need to be disposed to release unmanaged code. Using...End Using blocks handle this for us even if there is an error. To do this connections need to be declared in the Using in the method where they are used, not as class level variables.

Never concatenate strings with values to be entered in a database. This can lead to sql injection and damage your database. Always use parameters whose values are not considered as executable code by the database. I had to guess at the datatypes for the parameters. Check your database for actual types.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement