[quoted text, click to view] Phil wrote:
>> Again, it's the job of the provider's (MySQL's data access interface) to
>> handle all single quote issues--if you use it. Instead of passing raw SQL
>> to the engine, pass a parameterized query. The provider is responsible for
>> framing the strings properly.
>
> I'm new to .NET too. I think what Bill is saying is:
> instead of using:
>
> sql = "UPDATE table SET field='" & TextBox.Text & "'"
> cmd.ExecuteNonQuery(sql)
>
> you should use something like :
>
> sql = "UPDATE table SET field=@Field"
> cmd.Parameters.Add("@Field", OleDBType.VarChar).Value=TextBox.Text
> cmd.ExecuteNonQuery(sql)
>
> Is that right?
>
Sadly this doesn't work. I have the following code:
Dim dbParam As Data.Common.DbParameter
Command_DBt = Dbt.CreateCommand 'Dbt is the target mysql-ODBC connection)
strSQLCommand = "INSERT INTO afwijking (`afwijkid`, `grstid`, `dgrpid`,
`afwijking`) VALUES (@field0,@field1,@field2,@field3);"
Command_DBt.CommandText = strSQLCommand
Do While Reader_DBs.Read
For tel_fields = 0 To maxcount_fields - 1
dbParam = Command_DBt.CreateParameter
dbParam.DbType = DbType.Int64
dbParam.ParameterName = "@field" & tel_fields.ToString
dbParam.Value = Reader_DBs.GetValue(tel_fields)
Command_DBDoel.Parameters.Add(dbParam)
Next (tel_fields)
Command_DBDoel.ExecuteNonQuery()
Command_DBDoel.Parameters.Clear()
Loop
This is probably not to most efficient code but it should work. When i
look in the mysql query logs i get "INSERT INTO afwijking
(`afwijkid`,`grstid`,`dgrpid`,`afwijking`) VALUES
(@field0,@field1,@field2,@field3)". This means the parameters are not
replaced by the values. The MS-help is not very helpful in giving
examples or explanations. I've been googling for a day now but i can't
seem to find the problem.