注册商品的前台:
后台: 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(" <script type="text/javascript"> </script> "); } else Response.Write(" <script type="text/javascript"> </script> "); }