Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     //判断是否输入姓名、年龄、电话和家庭住址
     if (txtaddress.Text != "" && txtage.Text != "" && txtName.Text != "" && txtphone.Text != "")
     {
         if (txtphone.Text.Length != 11)   //如果电话号码错误
         {
             MessageBox.Show("电话号码位数不正确"); //弹出提示
         }
         else
         {
             linq = new linqtosqlDataContext(strCon);
             var resultChange = from info in linq.tb_User
                                where info.ID == Pid//创建linq,设置其根据ID值进行修改
                                select info;
             foreach (tb_User users in resultChange)
             {
                 users.User_Name     = txtName.Text;    //姓名
                 users.User_Sex      = cbbSex.Text;     //性别
                 users.User_Age      = txtage.Text;     //年龄
                 users.User_Marriage = cbbmary.Text;    //婚姻状况
                 users.User_Duty     = cbbduty.Text;    //职位
                 users.User_Phone    = txtphone.Text;   //电话
                 users.User_Address  = txtaddress.Text; //家庭地址
                 linq.SubmitChanges();                  //SubmitChanges方法提交修改
             }
             MessageBox.Show("修改成功");                   //弹出成功的提示
             binginfo();                                //重新绑定数据
         }
     }
 }
Esempio n. 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     //判断是否输入姓名、年龄、电话和家庭住址
     if (txtaddress.Text != "" && txtage.Text != "" && txtName.Text != "" && txtphone.Text != "")
     {
         if (txtphone.Text.Length != 11)//如果电话号码错误
         {
             MessageBox.Show("电话号码位数不正确");//弹出提示
         }
         else
         {
             linq = new linqtosqlDataContext(strCon);
             var resultChange = from info in linq.tb_User
                                where info.ID == Pid//创建linq,设置其根据ID值进行修改
                                select info;
             foreach (tb_User users in resultChange)
             {
                 users.User_Name = txtName.Text;//姓名
                 users.User_Sex = cbbSex.Text;//性别
                 users.User_Age = txtage.Text;//年龄
                 users.User_Marriage = cbbmary.Text;//婚姻状况
                 users.User_Duty = cbbduty.Text;//职位
                 users.User_Phone = txtphone.Text;//电话
                 users.User_Address = txtaddress.Text;//家庭地址
                 linq.SubmitChanges();//SubmitChanges方法提交修改
             }
             MessageBox.Show("修改成功");//弹出成功的提示
             binginfo();//重新绑定数据
         }
     }
 }