I am trying to save data to a database, but I keep getting an error when I try to save non string values:
The strSQl string is dim’das a string, since it goes into the sqlexecute statements. But how do you write to the database when some variables are strings and some are numbers or dates?
Tim,
When I convert all the data to strings, the database (where some fields are strings, other single, some date, etc) does not accept the strings into the numeric fields??
How does prepared statements get around the issue, Norman?
Of course it does. You want an SQL string of the form
Update mytable set myNumericField = 10
That all has to be in a string variable in order to pass it to SQLExecute. In code that looks something like
dim sqlstring as string
dim num as integer = 10
sqlstring = "update mytable set myNumericField = " + str(num)
You convert the number to a string so you can concatenate it into the main sql string. The database understands this syntax.
But Norman is right, PreparedStatements resolve all of this and more and are worth learning.
[quote=22935:@Gary Vassalotti]Tim,
When I convert all the data to strings, the database (where some fields are strings, other single, some date, etc) does not accept the strings into the numeric fields??
How does prepared statements get around the issue, Norman?[/quote]
You dont have to convert the data to strings at all