当前位置: 代码迷 >> ASP.NET >> 过程需要参数“”但未提供该参数!存储过程的有关问题!
  详细解决方案

过程需要参数“”但未提供该参数!存储过程的有关问题!

热度:374   发布时间:2013-02-25 00:00:00.0
过程需要参数“”但未提供该参数!!存储过程的问题!求救!
做了个简单的三层,向数据库中添加东西,用得存储过程,因为不太熟悉,所以一直出现问题,但是我却不知道究竟什么地方出现了问题!请教大家!

DAL层代码:
C# code
 public int InsertNews(Model.articlemodel SingleNews)         {                           string procname = "dbo.addnews";                SqlParameter[] prames ={                                           new SqlParameter("@title",SqlDbType.NVarChar,50),                                          new SqlParameter("@news_time",SqlDbType.DateTime),                                          new SqlParameter("@news_from",SqlDbType.NVarChar,50),                                          new SqlParameter("@news_class",SqlDbType.NVarChar,50),                                          new SqlParameter("@news_content",SqlDbType.NVarChar,200)};                prames[0].Value = SingleNews.title;                prames[1].Value = SingleNews.news_time;                prames[2].Value = SingleNews.news_from;                prames[3].Value = SingleNews.news_class;                prames[4].Value = SingleNews.news_content;                int intResult = DBUtility.DataBase.RunExecute(procname,prames);//后面注释部分                return intResult;                          // public static int RunExecute(string procName, SqlParameter[] prames)        {            SqlConnection conn = DBHelp.GetConn();            SqlCommand cmd = new SqlCommand();            cmd.CommandType = CommandType.StoredProcedure;            cmd.Connection = conn;            cmd.CommandText = procName;            conn.Open();            int intResult = cmd.ExecuteNonQuery();            conn.Close();            return intResult;        }                               }


BLL层:
C# code
public bool InsertNews(string title,DateTime news_time,string news_from,string news_class,string news_content)        {            bool Flage = false;            Dal.articledal ee = new Dal.articledal();            Model.articlemodel SingleNews = new Model.articlemodel();            SingleNews.title = title;            SingleNews.news_time = news_time;            SingleNews.news_from = news_from;            SingleNews.news_class = news_class;            SingleNews.news_content = news_content;            int intresult=ee.InsertNews(SingleNews);            if (intresult > 0)            {                Flage = true;            }                       return Flage;        }


WEB层:
C# code
protected void BtnAddNews_Click(object sender, EventArgs e)        {            string title = this.Txttitle.Text;            DateTime news_time = System.DateTime.Now;            string news_from = this.Txtnewsfrom.Text;            string news_class = this.DropDownList1.SelectedValue;            string news_content = this.Txtnewscontent.Text;            Bll.articlebll bll = new Bll.articlebll();            bool s=bll.InsertNews(title,news_time,news_from,news_class,news_content);                         if (s)              {                  LabMessage.Text = "添加新闻成功!";              }              else              {                  LabMessage.Text = "抱歉,新闻添加失败!";              }               }


存储过程如下:
  ALTER PROCEDURE dbo.addnews 

(
@title nvarchar(50)=erererrwrwer,
@news_time datetime,
@news_from nvarchar(50)=dgdgdgdfg,
@news_class nvarchar(50)=dfdgdgfgfg,
@news_content nvarchar(200)=fgggggggg
)

AS
insert into article(title,news_time,news_from,news_class,news_content) values(@title,@news_time,@news_from,@news_class,@news_content)
  相关解决方案