标签:sum 实体 添加 open data count int name load
Application - 全局公共变量组
存放位置:服务端
所有的访问用户都是访问的同一个变量
声明周期:永久
用法同session类似
viewstate-病例
因为http的无状态性,需要记录上一个页面的状态,因而需要一个viewstate记录上一个页面的状态,然后返回成相应的内容
纯HTML提交:
HTML界面:
要写action与method:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form action="Default.aspx" method="get"> 货品名称:<input type="text" name="t1"/><br /> 货品数量:<input type="text" name="t2"/><br /> 单价:        <input type="text" name="t3"/><br /> 进货时间:<input type="text" name="t4"/><br /> 联系电话:<input type="text" name="t5"/><br /> 仓库号:     <select id="Select1" name="t6"> <option>g01</option> <option>g02</option> <option>g03</option> </select> <br /> <input type="submit" value="提交" /> </form> </body> </html>
实体类:
using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> /// goods 的摘要说明 /// </summary> public class goods { public goods() { // // TODO: 在此处添加构造函数逻辑 // } public string goodsname { get; set; } public string number { get; set; } public string sprice { get; set; } public DateTime intime { get; set; } public string gtel { get; set; } public string goodsbase { get; set; } }
数据访问类:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.SqlClient; /// <summary> /// goodsdata 的摘要说明 /// </summary> public class goodsdata { SqlConnection conn = null; SqlCommand cmd = null; public goodsdata() { conn = new SqlConnection("server=.;database=data0928;user=sa;pwd=123"); cmd = conn.CreateCommand(); } public bool insert(goods g) { bool ok = false; int count = 0; cmd.CommandText = "insert into goods values(@a,@b,@c,@d,@e,@f)"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@a",g.goodsname); cmd.Parameters.AddWithValue("@b",g.number); cmd.Parameters.AddWithValue("@c",g.sprice); cmd.Parameters.AddWithValue("@d",DateTime.Now); cmd.Parameters.AddWithValue("@e",g.gtel); cmd.Parameters.AddWithValue("@f",g.goodsbase); conn.Open(); count = cmd.ExecuteNonQuery(); conn.Close(); if (count > 0) { ok = true; } return ok; } }
aspx界面:
using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { goods g = new goods(); g.goodsname = Request["t1"]; g.number = Request["t2"]; g.sprice = Request["t3"]; g.intime = Convert.ToDateTime(Request["t4"]); this.Title = g.intime.ToString(); g.gtel = Request["t5"]; g.goodsbase = Request["t6"]; bool ok = new goodsdata().insert(g); if (ok) { Response.Write("<script>alert(‘添加成功‘)</script>"); } } }
application、viewstate、纯HTML提交方式
标签:sum 实体 添加 open data count int name load
原文地址:http://www.cnblogs.com/wy1992/p/6250120.html