javastricpt查询Access数据库有一句怎么也搞不定,救命啊。
是做在线词典用的。javastricpt按照用户文本框输入查询Access数据库。
这一句怎么也搞不定了,怎么改都不对,痛苦了一天一夜了,求各位大侠请赐教。
var mySql = "SELECT * FROM table1 WHERE 发音=form1.txtjiansuo.text";
有朋友回答我说
var mySql = "SELECT * FROM table1 WHERE 发音='" & form1.txtjiansuo.text & "'";
可是提示“无效的SQL语句;期待‘delete’、‘insert’、‘procedure’、‘select’或‘update’”。
第一段可以执行。
--------------------------
function zhongying()
{
var mySql = "SELECT * FROM table1 WHERE 发音='nihao'";
var recordSet = database.Execute(mySql);
var tempText = "";
document.getElementById("dataDisplay").value = "";
while (!recordSet.EOF)
{
tempText = tempText + recordSet(0) + ":" +recordSet(2)+"【" +recordSet(3)+ "】"+ recordSet(4)+ recordSet(5)+"\n";
recordSet.MoveNext();
}
document.getElementById("dataDisplay").value = tempText;
recordSet.Close();
recordSet = null;
}
--------------------------
第二段的第一句出错了
(与第一段的区别就第一句,汗...用途是希望将用户在form1,id=txtjiansuo文本框中输入的值检索access表中发音字段)
function yingzhong()
{
var mySql = "SELECT * FROM table1 WHERE 发音=form1.txtjiansuo.text";
var tempText = "";
var recordSet = database.Execute(mySql);
document.getElementById("dataDisplay").value = "";
while (!recordSet.EOF)
{
tempText = tempText + recordSet(0) + ":" +recordSet(2)+"【" +recordSet(3)+ "】"+ recordSet(4)+ recordSet(5)+"\n";
recordSet.MoveNext();
}
document.getElementById(dataDisplay).value = tempText;
recordSet.Close();
recordSet = null;
}
------解决方案--------------------
var mySql = "SELECT * FROM table1 WHERE 发音=form1.txtjiansuo.text";
改成:
var mySql = "SELECT * FROM table1 WHERE 发音 = \'form1.txtjiansuo.text\'";
------解决方案--------------------
var mySql = "SELECT * FROM table1 WHERE 发音 = \'form1.txtjiansuo.text\'";
单引号前面加上转义符