日期:2014-05-18 浏览次数:20587 次
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; } }
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; }
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 = "抱歉,新闻添加失败!"; } }