我需要一些关于邻近搜索的帮助。我需要在房地产数据库上运行一个 select 语句,以确定最接近搜索条件的顶部行(用户输入的数字)。然后我需要在 gridview 控件中显示这些值。
我不知道如何添加多个计算列的值以创建具有接近结果的最后一列。
有人可以帮我弄清楚如何将多个计算列汇总为一列,然后按此列分组吗?
以下是我尝试过的代码,但出现错误异常。
aQueryString = "SELECT Top " + txtNumRows.Text;
aQueryString += "propno, ";
if (txtMaxAsk.Text != "")
aQueryString += "askprice, ";
aQueryString += "sqr(((askprice - " + txtMaxAsk.Text;
aQueryString += ")/1000000)^2) AS m1,";
if (txtMinSqFt.Text != "")
aQueryString += "sqft, ";
aQueryString += "sqr(((sqft - " + txtMinSqFt.Text;
aQueryString += ")/6000)^2) AS m2 ";
aQueryString += "sum(m1) + sum(m2) FROM property ORDER BY 4 ";
anAccessCommand = anAccessConnection.CreateCommand();
anAccessCommand.CommandText = aQueryString;
gvProperty.DataSource = anAccessCommand.CommandText;
anAccessReader = anAccessCommand.ExecuteReader();
gvProperty.DataSource = anAccessReader;
gvProperty.Visible = true;
try
{
gvProperty.DataBind();
}
catch (Exception ex)
{
Response.Write("Binding exception in Button1_Click<BR>");
Response.Write("Access Exception Handler: {0} " + ex.ToString());
}
这是我得到的 OleDbException:
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.