houtai/add_article.aspx.cs

(完整代码) 2KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace 电子商务.houtai
{
    public partial class add_article : System.Web.UI.Page
    {
        SQLHelper db = new SQLHelper();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
                if (!IsPostBack)
                {
                    this.txt_date.Text = DateTime.Now.Date.ToString();
                }
            }
        }
        public void bind()
        {
            string sql = "select * from category";
            DataTable dt = db.ExecuteQuery(sql, CommandType.Text);
            this.ddl_category.DataSource = dt;
            this.ddl_category.DataTextField = "category";
            this.ddl_category.DataValueField = "c_id";
            this.ddl_category.DataBind();
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            this.txt_author.Text = "";
            
            this.txt_title.Text = "";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = "insert into news(title,author,news_date,ms,c_id) values(@title,@author,@news_date,@content,@c_id)";
            SqlParameter[] paras = new SqlParameter[] 
               { 
            new SqlParameter("@title",this.txt_title.Text),
            new SqlParameter("@author",this.txt_author.Text),
            new SqlParameter("@news_date",this.txt_date.Text),
            new SqlParameter("@content",this.fck.Value.ToString()),
            new SqlParameter("@c_id",int.Parse(this.ddl_category.SelectedValue.ToString())),
               };
            SQLHelper db = new SQLHelper();
            int result = db.ExecuteNonQuery(sql, paras, CommandType.Text);
            Response.Write("<script>alert('添加成功!');location='add_article.aspx'</script>");
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。