I'am two thirds of the way along with my project but for this one line.
I have 3 dropdown lists where I'am trying to take there selected values and update my database.
My program seems to be getting these values yet they wont go in.
I hope my attached pictures below highlight the problem further. Any help on getting this
to work would be amazing. Thanks so much in advance, I really appreciate it.
When concatenating strings you should use & rather than +
When concatenating numeric vars into your string you should use the .ToString method which is the source of the error in your picture.
MyString ="Some Text " & MyNumber.ToString & " More Text"
That solved it.
This is the updated line of code that I changed:
Code:
sqlString = "UPDATE tbl_batch SET orignal = " & shift & " WHERE batchNumber = '" & batch & "' AND jobId = " & job & " "
Notice my batch parameter is a string so it must be wrapped in single quotes.
You were absolutely right I was using the wrong concatenation for strings i.e. + is wrong, & is right ...
In vb 6 it is ----> &
in vb.net it is -----> +
in vb.net and Mysql once again it is -----> &
In vb 6 it is ----> &
in vb.net it is -----> +
in vb.net and Mysql once again it is -----> &
Actually it is & in all versions of VB after VB3 including all versions of VB.Net
+ will work in all of them as well but you should always use & as of VB4 and later
You should also be using .ToString on those values that are numeric vars. such as shift should be shift.ToString
I take it that you do not have option strict enabled as it would be triggering an error complaining about mixing variable types if it were
I will correct that change thank you, i relatively new to this language and this help is great. when you say "option strict enabled" what does this mean and how would it be an advantage to me?
Basically it forces a more strict method of coding and can help to eliminate runtime errors by alerting you to them when you are still in the IDE. There are options in the IDE for Option Explicit and Option Strict.
Option Explicit forces you to declare all variables before using them.
Option Strict forces you to use the correct variable types or conversions.
For example you can combine a string and an integer if Option strict is off but if it is on you must convert one of them to the type of the other. You could add a double to a long without it on but with it will require you to make a conversion or use a different var.
Basically these options force you to write better code and reduce the chance that your program will crash due to miss use of a variable
Bookmarks