这个的正确格式是什么??我有一个语法错误

What is the correct format of this?? I have a syntax error

OleDbDataAdapter da = new OlDbDataAdapter("SELECT * FROM[Sheet1$] Where Dormitory"+comboBox2.SelectedItem+" Where City"+comboBox1.SelectedItem+"",baglan);

我有语法错误。 这个的正确格式是什么??

你把 WHERE 放了两次而不是把 AND 放在第二位 & 忘了放 =

OleDbDataAdapter da = new OlDbDataAdapter(@"SELECT * FROM[Sheet1$] 
   Where Dormitory='"+comboBox2.SelectedItem+"' AND City='"+comboBox1.SelectedItem+"'",baglan);

注意:它容易受到 SQLI 的攻击。最好使用准备好的语句。

编辑:正如@Thorsten Dittmar 所说,如果使用带空格的字符串,则应使用单引号