I want to run parameterized SQL with .NET. But when I use AddWithValue() the generated command does not work.
SqlCommand cmd = new SqlCommand("SELECT * FROM table WHERE table.name = @A")
cmd.Parameters.AddWithValue("@A", "A string");
Generates this sql command:
exec sp_executesql N'SELECT * FROM table WHERE table.name = @A',N'@A nvarchar(10)',@A=N'''A string'''
But that command returns no value while the following command returns the value I want (i.e. matches one row):
SELECT * FROM table WHERE table.name = 'A String'
The second query does what I expect, and I expect both queries to return the same result.
What am I doing wrong in the code?