注册商品

来源:互联网 发布:vb循环语句do while 编辑:程序博客网 时间:2024/04/30 23:39

注册商品的前台:

添加商品商品类别  商品名称 商品单价  进入商品列表

后台: public partial class NewProduct : System.Web.UI.Page { // 添加商品 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlHelper s = new SqlHelper(); string cmtext = "select * from T_GoodsType"; DataTable dt = s.GetTable(cmtext, null, CommandType.Text); DropDownList1.DataSource = dt; DropDownList1.DataTextField = "TypeName"; DropDownList1.DataValueField = "TypeID"; DropDownList1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { int typeid = int.Parse(DropDownList1.SelectedValue); string goodname = GoodName.Text.Trim(); string goodprice = GoodPrice.Text.Trim(); SqlHelper s = new SqlHelper(); string cmtext = "insert into T_GoodsInfo(TypeID,GoodsName,GoodsPrice)values(@typeid,@goodname,@goodprice)"; SqlParameter[] paras ={ new SqlParameter ("typeid",SqlDbType.Int), new SqlParameter ("@goodname",SqlDbType.VarChar), new SqlParameter ("@goodprice",SqlDbType.Float) }; paras[0].Value = typeid; paras[1].Value = goodname; paras[2].Value = goodprice; int result = s.ExecuteNoQuery(cmtext, paras, CommandType.Text); if (result > 0) { Response.Write(""); } else Response.Write(""); }

原创粉丝点击