初学linq (1)

l.增

     try
          {
            crmDataContext myc = new crmDataContext();
            con.Beizhu = remark;
            if (pathName != "")
            {
                //保存图片
                System.IO.FileStream fs =
                       new System.IO.FileStream(pathName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] bufferByte = new byte[fs.Length];
                fs.Read(bufferByte, 0, (int)fs.Length);
                fs.Close();
                fs = null;
                con.MyPic = bufferByte;
            }

            myc.Contact.InsertOnSubmit(con);
            myc.SubmitChanges();
            MessageBox.Show("保存成功");
            this.Close();
            //重新绑定GridvIEW
            tls.bdLinker();
            }

      catch()

       {

        }

2.改

            crmDataContext myc2 = new crmDataContext();

            var vContect = from p in myc2.Contact
                           where p.cid == Convert.ToInt32(_id)
                           select new { p };

            Contact con2 = myc2.Contact.Where(p => p.cid.ToString() == _id).First();
            con2.Name = name;
            con2.FirstChar = getSpells(name);
            con2.QQ = qq;
            con2.Web = website;
            con2.Shengshi = shengshi;
            con2.Shixian = shixian;
            con2.Jiedao = street;
            con2.Beizhu = remark;
            if (pathName != "")
            {
                //保存图片
                System.IO.FileStream fs =
                       new System.IO.FileStream(pathName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] bufferByte = new byte[fs.Length];
                fs.Read(bufferByte, 0, (int)fs.Length);
                fs.Close();
                fs = null;
                con2.MyPic = bufferByte;
            }

            myc2.SubmitChanges();
            MessageBox.Show("修改成功!");

3.删

  if (_callID != "")
            {
                try
                {
                    crmDataContext mcc = new crmDataContext();
                    var vContect = from p in mcc.call
                                   where p.id == Convert.ToInt32(_callID)
                                   select new { p };

                    call cl = mcc.call.FirstOrDefault(a => a.id.ToString() == _callID);
                    mcc.call.DeleteOnSubmit(cl);
                    mcc.SubmitChanges();
                    MessageBox.Show("删除成功!");
                    bddgvTHJL();
                }
                catch
                {
                    MessageBox.Show("删除失败!");
                }
            }

4.查

 crmDataContext cdcL = new crmDataContext();
                var aa = from p in cdcL.lines
                         where p.Line==Convert.ToInt32(_line)
                         select p;
               this.lblTD.Text= aa.FirstOrDefault().Line.Value.ToString();
               tbTDName.Text = aa.FirstOrDefault().Phone;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值