0

Working on setting up a SqlDataSource connecting MySQL database to a ASP .NET GridView.

The Delete Command is:

DeleteCommand="DELETE FROM troutetracking WHERE id=?id" 

The Delete parameter is:

<DeleteParameters>
     <asp:Parameter Name="id"  Type="Int32" />
</DeleteParameters>

When I run a delete link on the Gridview the following error message appears:

MySql.Data.MySqlClient.MySqlException: Parameter '?id' must be defined.

What is the proper syntax?

2 Answers 2

1

That is covered in MSDN's documentation:

Because different database products use different varieties of SQL, the syntax of the SQL string depends on the current ADO.NET provider being used, which is identified by the ProviderName property. If the SQL string is a parameterized query or command, the syntax of the parameter also depends on the ADO.NET provider being used. For example, if the provider is the System.Data.SqlClient, which is the default provider for the SqlDataSource class, the syntax of the parameter is '@parameterName'. However, if the provider is set to the System.Data.Odbc or System.Data.OleDb, the placeholder of the parameter is '?'. For more information about parameterized SQL queries and commands, see Using Parameters with the SqlDataSource Control.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the clarification Remy. What is confusing me is that for a UPDATE query the ?id syntax is used but for the DELETE query the ?id doesn't work.
The syntax should be the same for both, as it is based on what SQL provider is being used, not what kind of SQL statement is being executed.
0

This blog ran into a similar issue:

link text

What I needed to do was update the connection to string to contain "Allow User Variables=True".

I did this by using the 'Advanced' button when setting up the data source.

The delete query also needed to be tweaked to be:

DeleteCommand="DELETE FROM troutetracking WHERE id=@id" 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.