日期:2014-05-18  浏览次数:20416 次

过程或函数 'news_SelectBycaId' 需要参数 '@caid',但未提供该参数。
C# code

NewsDao.cs
        #region 根据新闻类别Id取出该类别下的所有新闻
        public DataTable SelectByCaId(int caid)
        {
            DataTable dt = new DataTable();
            string cmdText = "news_SelectBycaId";
            SqlParameter[] paras = new SqlParameter[] { 
                new SqlParameter("@caid",caid)
            };
            dt = sqlhelp.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure);
            return dt;
        }
        #endregion

NewsManager.cs
        #region 根据新闻类别Id取出该类别下的所有新闻

        public DataTable SelectByCaId(int caid)
        {
            return newsDao.SelectByCaId(caid);
        }
        #endregion
List.aspx.cs
 if (!Page.IsPostBack)
        {
            string caid= Request.QueryString["caid"];
            //绑定新闻列表
            gvNews.DataSource = new NewsManager().SelectByCaId(caid);
            gvNews.DataBind();
        }


存储过程
SQL code

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[news_SelectBycaId]
@caid int
AS
BEGIN
    select n.id,n.title,n.createTime,c.caName , n.caId from _news n
    inner join _category c on n.caId=c.id and n.caId=@caid
    order by n.createTime desc
END





------解决方案--------------------
检查ExecuteQuery方法。参数是否添加到cmd