I've been trying to send a long MySQL command in vb.NET. When I want to use variables as part of the MySQL command string I've been concatenating the string using "&".
This works, but makes my code look messy, so I tried using "{0}, {1}" etc.
This however does not work and I get the error:
Overload resolution failed because no accessible 'New' accepts this number of arguments.
Examples:
connector.Open()
commander = New MySqlCommand("UPDATE 'pupil_data' SET '" & Question & "'='" & Answer & "' WHERE 'username'=" & Environment.UserName & ";", connector)
dataAdapter = New MySqlDataAdapter(commander)
connector.Close()
This works, however:
connector.Open()
commander = New MySqlCommand(("UPDATE 'pupil_data' SET '{0}'='{1}' WHERE 'username'='{2}'", Question, Answer, Environment.Username), connector)
dataAdapter = New MySqlDataAdapter(commander)
connector.Close()
Doesn't work. It could just be a problem with my bracketing but I've tried several combinations and it's logically sound (I think).