Incorrect syntax near ‘FROM’.

I am getting this error when running a getAll function and would appreciate someone to look though it for help.

 public SqlDataReader FetchAll(string tableName) { SqlDataReader reader; using (SqlConnection conn = new SqlConnection(ConnectionString)) { string query = "SELECT * FROM " + tableName; using (SqlCommand command = new SqlCommand(query, conn)) { conn.Open(); reader = command.ExecuteReader(); } } return reader; } 

it's to do with

Line 42: //uses the reader to execute command Line 43: reader = command.ExecuteReader();

therefore I guess I do command.ExecuteNonQuery(); instead but i still need to somehow return a value?

by HelperSanta via /r/csharp

Leave a Reply