MySQL和C Sharp数据集集成

时间:2014-02-27 20:19:02

标签: c# mysql

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

我的注释行有问题,由于某些原因我无法使其工作,是什么导致了这个? 感谢。

0 个答案:

没有答案