I am attempting to run a query using a parameter in C#. I am getting an issue where no rows are being returned. I am pulling the sql from a file and putting it into the command text. When the query (a SELECT statement) is run, no results are returned. I have confirmed that the result is in my database and that the query is correct (after replacing the param) by running it normally.
conn.Open();
//create the command
var command = conn.CreateCommand();
//Read sql from file
FileInfo file = new FileInfo("SQL/GetPage.sql");
string script = file.OpenText().ReadToEnd();
command.CommandText = script;
command.Parameters.AddWithValue("?PageID", PageName);
command.Prepare();
MySqlDataReader rdr = command.ExecuteReader();
rdr.Read();
SQL:
SELECT * FROM `Page` WHERE PageID = '?PageID'
I have tried with both the prepare and without it. I have no clue why it is not working. Also, I am only expecting one result max (PageID is unique), so that is why it isn't in a loop. I also know my connection is good because I hardcoded the query without the where clause and it worked fine.
Please let me know if anyone has any suggestions.
Thanks