Thursday, 12 September 2013

Strange behaviour with C# SQL

Strange behaviour with C# SQL

string sql = "SELECT column1 FROM table1 INNER JOIN table2 ON
table1.table2ID = table2.table2ID where column1 = \"testData\"";
using (var command = new SqlCommand(sql, connection))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader["column1"].ToString());
}
Console.ReadLine();
}
}
The above SQL query works fine when there is without the where clause and
I able to writeline "testData". But when I restrict the condition, then
its giving me sqlException saying that "testData" is an invalid column?

No comments:

Post a Comment