这是我的代码:
command.CommandText =
"SELECT DISTINCT B.* FROM BlankFormSubmissions B, Actions A WHERE B.FormName = " +
GenericRoutines.SqlFmt(form.Name) +
" AND B.ProcessName = A.ProcessName AND B.ActionName = A.ActionName" +
" ORDER BY B.ID";
OleDbDataReader reader = command.ExecuteReader();
SQL是:
SELECT DISTINCT B.*
FROM BlankFormSubmissions B, Actions A
WHERE B.FormName = 'FindingNemo'
AND B.ProcessName = A.ProcessName
AND B.ActionName = A.ActionName
ORDER BY B.ID
答案 0 :(得分:4)
我通过在Access中运行SQL发现,我实际上只是引用了Access表中不存在的列(FormName)。
答案 1 :(得分:0)
您需要引用您传递给查询的任何字符串。试试:
command.CommandText = "SELECT DISTINCT B.* FROM BlankFormSubmissions B, Actions A WHERE B.FormName = '" +
GenericRoutines.SqlFmt(form.Name) + "' AND B.ProcessName = A.ProcessName AND B.ActionName = A.ActionName" +
" ORDER BY B.ID";
使用参数化查询或存储过程来更容易(一旦你克服了所涉及的小学习曲线)和更好(更整洁,更安全)这种事情。
HTH。