查询表达式status = 'Available'中出现语法错误(缺少运算符)
本文关键字:错误 语法 运算符 表达式 查询表 status 查询 Available | 更新日期: 2023-09-27 18:13:46
我正在使用c# Windows应用程序连接到MS Access。我正在用特定的查询填充datagridview,但这发生了
查询表达式"Model WHERE Status = 'AVAILABLE'"语法错误(缺少运算符)。
在此查询
OleDbDataAdapter daAvailable = new OleDbDataAdapter("SELECT Type, Brand, Model, SerialNo, Status, Remarks, RAM, HDD, ODD, VideoCard, PS FROM Available ORDER BY Type, Brand, Model WHERE Status = 'AVAILABLE'", cnn);
我该怎么办?
这是我的代码
OleDbConnection cnn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:'Users'james'Documents'Visual Studio 2010'Projects'Vault'Vault'VaultDatabase.accdb");
DataSet dstAvailable = new DataSet();
DataSet dstData = new DataSet();
DataSet dstDeployment = new DataSet();
DataSet dstLog = new DataSet();
public void FillAvailable(DataGridView dgv)
{
OleDbDataAdapter daAvailable = new OleDbDataAdapter("SELECT Type, Brand, Model, SerialNo, Status, Remarks, RAM, HDD, ODD, VideoCard, PS FROM Available ORDER BY Type, Brand, Model WHERE Status = 'AVAILABLE'", cnn);
daAvailable.Fill(dstAvailable);
dgv.DataSource = dstAvailable.Tables[0];
}
这样写
public void FillAvailable(DataGridView dgv)
{
OleDbDataAdapter daAvailable = new OleDbDataAdapter("SELECT Type, Brand, Model, SerialNo, Status, Remarks, RAM, HDD, ODD, VideoCard, PS FROM Available WHERE Status = 'AVAILABLE' ORDER BY Type, Brand, Model", cnn);
daAvailable.Fill(dstAvailable);
dgv.DataSource = dstAvailable.Tables[0];
}
*Order By在Where之后*
,
总是在WHERE子句之后,应该是:
OleDbDataAdapter daAvailable = new OleDbDataAdapter("SELECT Type, Brand, Model, SerialNo, Status, Remarks, RAM, HDD, ODD, VideoCard, PS FROM Available WHERE Status = 'AVAILABLE' ORDER BY Type, Brand, Model", cnn);
ORDER BY
子句应该位于SQL
WHERE
子句之后所以你的查询应该是:
OleDbDataAdapter daAvailable = new OleDbDataAdapter("SELECT Type, Brand, Model, SerialNo, "+
"Status, Remarks, RAM, HDD, ODD, VideoCard, PS " +
"FROM Available " +
"WHERE Status = 'AVAILABLE' "+
"ORDER BY Type, Brand, Model", cnn);
//The above query is broken down on multiple lines for clarity