1

I just want to ask what is the difference between ? and @ when inserting data to mysql in visual basic. So I have this query:

Dim sql As String = "INSERT INTO users(firstname, lastname, position) VALUES(?fname, ?lname, ?pos)"

cmd = New MySqlCommand(sql, conn)
cmd.Parameters.AddWithValue("?fname", TextBox1.Text)
cmd.Parameters.AddWithValue("?lname", TextBox2.Text)
cmd.Parameters.AddWithValue("?pos", TextBox3.Text)

I first use the @param but it is not inserting data to mysql but when I use ?param it inserts data. What is the difference between them?

Rak
  • 139
  • 5
  • 20
  • Please check your tags and [edit](https://stackoverflow.com/posts/46617097/edit) the question to use appropriate ones. (I think you probably want [vb.net] instead of [vba], and [visual-studio] and [visual-studio-2010] are definitedly inappropriate for this question.) – YowE3K Oct 07 '17 at 05:57
  • https://stackoverflow.com/questions/23691801/mysql-connector-nets-mysqlcommand-not-using-parameters – Tim Williams Oct 07 '17 at 06:07
  • have you tried to use @ also in AddWithValue function? – Mr.J Oct 07 '17 at 06:15

1 Answers1

1

When CommandType is set to Text, the .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand. In either of these cases, use the question mark (?) placeholder.

Direct quote from here:

named parameters with .NET Framework Data Provider for ODBC

QHarr
  • 83,427
  • 12
  • 54
  • 101