为对象提供的参数不是函数。如果参数用作表提示,则需要WITH关键字

时间:2013-05-03 00:33:37

标签: c# asp.net sql-server sql-server-2008-r2

我正在运行Windows 7和II7以及SQL Server 2008 R2。我有一个aspx程序,当我尝试运行它时,我收到以下错误

  

为对象'us​​ers'提供的参数不是函数。如果   这些参数用作表提示,WITH关键字是   必需的。

我编码的是:

  public ArrayList GetGoodsList(string type, string goodsType, string user, string payType, bool flag)
    {
        conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["Conn"].ToString());

        DataSet ds = new DataSet();
        sSql = "select count(*) from users('" + type + "','" + goodsType + "','" + user + "','" + payType + "')";
        if (flag == true)
        {
            sSql += "where IsCommend = 1";
        }

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = sSql;
        conn.Open();
        int maxRow = Int32.Parse(cmd.ExecuteScalar().ToString());

        sSql = "select * from users('" + type + "','" + goodsType + "','" + user + "','" + payType + "')";
        if (flag == true)
        {
            sSql += "where IsCommend = 1";
        }
        cmd.CommandText = sSql;
        SqlDataReader reader = cmd.ExecuteReader();

        ArrayList gInfos = new ArrayList();
        GoodsInfo gInfo;

        for (int i = 0; i < maxRow; i++)
        {
            if (reader.Read())
            {
                gInfo = new GoodsInfo();
                gInfo.G_ID = Int32.Parse(reader["G_ID"].ToString());
                gInfo.G_Name = reader["G_Name"].ToString();
                gInfo.Type = reader["Type"].ToString();
                gInfo.GoodsType = reader["GoodsType"].ToString();
                gInfos.Add(gInfo);
            }
        }
        conn.Close();
        return gInfos;
    }

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

SELECT声明sSql = ...

中,您的问题没有给出答案

这不是正确的SQL语法。

SELECT声明中阅读this wikipedia article