zoukankan      html  css  js  c++  java
  • Linq To Entity 的增删改查(技术储备,怕忘了) jerry

    1.新增Customers记录
                using (NorthwindEntities myDb = new NorthwindEntities())
                {
                    Customers customer = new Customers();
     
                    Random rm = new Random();
     
                    customer.CustomerID = "A" + rm.Next(9999).ToString();
                    customer.CompanyName = "EntLib.com Forum";
                    customer.Address = "http://www.EntLib.com";
     
                    myDb.AddToCustomers(customer);
     
                    int count = myDb.SaveChanges();
     
                    txtCustomerID.Text = customer.CustomerID;
                }
     
    2.更新Customers记录
                using (NorthwindEntities myDb = new NorthwindEntities())
                {
                    var query = from customer in myDb.Customers
                                where customer.CustomerID == txtCustomerID.Text.Trim()
                                select customer;
     
                    foreach (var row in query)
                    {
                        row.CompanyName = "Updated Company Name";
                    }
     
                    myDb.SaveChanges();
                }
     
    3.删除Customers记录
                using (NorthwindEntities myDb = new NorthwindEntities())
                {
                    var query = from customer in myDb.Customers
                                where customer.CustomerID == txtCustomerID.Text.Trim()
                                select customer;
     
                    foreach (var row in query)
                    {
                        myDb.DeleteObject(row);
                    }
     
                    myDb.SaveChanges();
                }
     
    4.查询Customers,返回所有记录
                using (NorthwindEntities myDb = new NorthwindEntities())
                {
                    dataGridView1.DataSource = myDb.Customers;
                }

  • 相关阅读:
    python处理yml
    awk命令笔记
    微信小程序wxml的数据传给js 点击事件 js获取view中的内容
    微信小程序js 字符串截取
    微信小程序 wx:if 多条件判断
    微信小程序 --- toast消息提示框
    微信小程序 点击事件获取到的 event.currentTarget.dataset.id 是空的 解决办法
    微信小程序页面跳转传参数
    微信小程序开发框架
    微信小程序获取当前时间
  • 原文地址:https://www.cnblogs.com/mbailing/p/1846302.html
Copyright © 2011-2022 走看看