예제 #1
0
 //将数据更新到数据库
 private void btn_Edit_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)//遍历所有行
     {
         linq = new linqtosqlDataContext(strCon);//创建linq连接对象
         tb_XML xml = new tb_XML();//创建tb_XML对象
         xml.ID = dataGridView1.Rows[i].Cells[3].Value.ToString();//为ID赋值
         xml.Name = dataGridView1.Rows[i].Cells[0].Value.ToString();//为Name赋值
         xml.Sex = dataGridView1.Rows[i].Cells[1].Value.ToString();//为Sex赋值
         xml.Salary = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);//为Salary赋值
         linq.tb_XML.InsertOnSubmit(xml);//提交数据
         linq.SubmitChanges();//执行对数据库的修改
         linq.Dispose();//释放linq对象
     }
     MessageBox.Show("成功将XML中的数据更新到了数据库中!");//弹出提示
 }
예제 #2
0
 //将数据更新到数据库
 private void btn_Edit_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)                  //遍历所有行
     {
         linq = new linqtosqlDataContext(strCon);                            //创建linq连接对象
         tb_XML xml = new tb_XML();                                          //创建tb_XML对象
         xml.ID     = dataGridView1.Rows[i].Cells[3].Value.ToString();       //为ID赋值
         xml.Name   = dataGridView1.Rows[i].Cells[0].Value.ToString();       //为Name赋值
         xml.Sex    = dataGridView1.Rows[i].Cells[1].Value.ToString();       //为Sex赋值
         xml.Salary = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value); //为Salary赋值
         linq.tb_XML.InsertOnSubmit(xml);                                    //提交数据
         linq.SubmitChanges();                                               //执行对数据库的修改
         linq.Dispose();                                                     //释放linq对象
     }
     MessageBox.Show("成功将XML中的数据更新到了数据库中!");                                 //弹出提示
 }