• 12.16 wedfrom 查询.添加.修改.删除


    查询,传值
    DataClassesDataContext cont = new DataClassesDataContext();
    
            Repeater1.DataSource = cont.House;
            Repeater1.DataBind(); 
    
    
    添加
    DataClassesDataContext cont = new DataClassesDataContext();
    
            if (TextBox1.Text != "")
            {
                try
                {
                    //取值
                    string KeyWord = TextBox1.Text;
                    string Area = TextBox2.Text;
                    string SquareMeter = TextBox3.Text;
                    string Rent = TextBox3.Text;
                    string RentType = TextBox3.Text;
                    string HouseType = TextBox3.Text;
    
                    //造对象
                    House data = new House();
                    data.KeyWord = KeyWord;
                    data.Area = Area;
                    data.SquareMeter = Convert.ToInt32(SquareMeter);
                    data.Rent = Convert.ToInt32(Rent);
                    data.RentType = RentType;
                    data.HouseType = HouseType;
    
                    //添加到数据库
                    cont.House.InsertOnSubmit(data);
                    cont.SubmitChanges();
                    qingkong();
    	    }
    
    添加:
        protected void Button1_Click(object sender, EventArgs e)
        {
            TestDataContext context = new TestDataContext();
    
            string code = txtCode.Text;
            string name = txtName.Text;
            decimal price = Convert.ToDecimal( txtPrice.Text);
            string source = txtSource.Text;
            int numbers = Convert.ToInt32( txtNumbers.Text);
    
            Fruit data = new Fruit();
            data.Ids = code;
            data.Name = name;
            data.Price = price;
            data.Source = source;
            data.Numbers = numbers;
    
            context.Fruit.InsertOnSubmit(data);
            context.SubmitChanges();
    
            Clear();
        }
    修改:
    	//先根据 ids 主键 读取数据显示到文本框中
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string ids = Request["ids"].ToString();
    
                TestDataContext context = new TestDataContext();
    
                Fruit data = context.Fruit.Where(p => p.Ids == ids).First();
                txtCode.Text = data.Ids;
                txtName.Text = data.Name;
                txtPrice.Text = data.Price.ToString();
                txtSource.Text = data.Source;
                txtNumbers.Text = data.Numbers.ToString();
            }
    
        }
    	//修改代码
        protected void Button1_Click(object sender, EventArgs e)
        {
            TestDataContext context = new TestDataContext();
            string code = txtCode.Text;
            string name = txtName.Text;
            decimal price = Convert.ToDecimal(txtPrice.Text);
            string source = txtSource.Text;
            int numbers = Convert.ToInt32(txtNumbers.Text);
    
            Fruit data = context.Fruit.Where(p=>p.Ids==code).First();
    
            data.Name = name;
            data.Price = price;
            data.Source = source;
            data.Numbers = numbers;
    
            context.SubmitChanges();
        }
    
    删除:
    	//根据 ids 主键  删除
        protected void Page_Load(object sender, EventArgs e)
        {
            string ids = Request["ids"].ToString();
            TestDataContext context = new TestDataContext();
    
            Fruit data = context.Fruit.Where(p=>p.Ids==ids).First();
    
            context.Fruit.DeleteOnSubmit(data);
            context.SubmitChanges();
    
            Response.Redirect("Default.aspx");
    
        }
    

      

      

  • 相关阅读:
    使用air16sdk打包ipa报错
    笔试题目
    网络编程Socket之UDP
    网络编程Socket之TCP
    Spring的HelloWorld
    一起学makefile
    使用Eclipse创建Hibernate工程
    log4j日志输出使用教程
    监听tomcat服务器启动/关闭并从配置文件中读取参数进行初始化
    java加载配置文件
  • 原文地址:https://www.cnblogs.com/jlhea/p/5083006.html
Copyright © 2020-2023  润新知