0

I am using Mysql .Net Connector to access a database in C#. I get an FormatException when I try to execute a statement with parameter. Here is my code:

MySqlCommand comm = connection.CreateCommand();
comm.CommandText = "SELECT id_ FROM journalarticle WHERE title LIKE ?title";
comm.Parameters.Add("?title", DbType.AnsiString).Value = title;
MySqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
   id = reader.GetInt32(0);
}
comm.Dispose();
reader.Dispose();
1
  • 1
    Also, and this can sometimes be a preference thing, but if you didn't know about the using statement instead of calling dispose you should, it's marvellous in my opinion: ryanfarley.com/blog/archive/2004/03/18/447.aspx Commented Jul 29, 2011 at 13:34

1 Answer 1

2

Isn't it an @ symbol not a '?'

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

6 Comments

Does your SQL run on its own, as in returns expected result in MS SQL Manager?
What? I don't understand your question.
If you open up Microsoft SQL Manager (Express if you don't have paid for) does your Select statement return the expected result? Select blah from blah where blah like blah
I have to admit I might be being ignorant here but can you not just replace 'DbType.AnsiString' with 'title' as in comm.Parameters.Add("?title", title);
Can you mark it up as the answer please =) Why were you using 'DbType.AnsiString' anyway?
|

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.