public int InsertAd(AdModel ads) { SqlParameter[] param = { new SqlParameter("@Name", SqlDbType.VarChar, 20), new SqlParameter("@PhotoPath", SqlDbType.VarChar,255), new SqlParameter("@Url",SqlDbType.VarChar,255) }; param[0].Value = ads.AdName; param[1].Value = ads.PhotoPath; param[2].Value = ads.Url; int result = SqlHelp.ExecuteNonQuery("prc_InsertAd", CommandType.StoredProcedure, param); return result; }
protected void Add_Click(object sender, EventArgs e) { AdModel ads = new AdModel(); ads.AdName = txtName.Text.Trim(); ads.Url = txtUrl.Text.Trim(); ads.PhotoPath = path; bool flag = bll.InsertAd(ads); if (flag) { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('添加成功');location.href='AdsInfo.aspx';</script>"); } else { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('添加失败');</script>"); } }
public List<AdModel> ShowAllAd() { SqlDataReader dr = SqlHelp.ExecuteReader("prc_ShowAllAd", CommandType.StoredProcedure); List<AdModel> list = new List<AdModel>(); while (dr.Read()) { AdModel ad = new AdModel(); ad.ID = Convert.ToInt32(dr[0]); ad.AdName = dr[1].ToString(); ad.PhotoPath = @"~\" + dr[2].ToString(); ad.Url = dr[3].ToString(); ad.AddDate = Convert.ToDateTime(dr[4]); list.Add(ad); } dr.Close(); return list; }
public bool InsertAd(AdModel ad) { int result = dal.InsertAd(ad); return result == 0 ? false : true; }