string table='table';
conn = new MySqlConnection(cs);
conn.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT * from @table";
cmd.Parameters.AddWithValue("@table", table);
cmd.Prepare();
//MySqlDataAdapter adapter = new MySqlDataAdapter(cmd); // Doesn't work.
MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * from test",conn); // WORKS.
DataSet DS = new DataSet();
adapter.Fill(DS);
return DS.Tables[0]; //SQL syntax error near 'table' error at this line
我的注释行有问题,由于某些原因我无法使其工作,是什么导致了这个? 感谢。