电话记录管理的制作4(更改篇)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 private void dataGridView1_DoubleCellClick(object sender, DataGridViewCellEventArgs e) 2 { 3 DialogResult result = MessageBox.Show("是否要修改当前行中单元格的内容?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question); 4 if (result == DialogResult.Yes) 5 { 6 Form4 form4 = new Form4(); 7 form4.Show(); 8 string headname = dataGridView1.Columns[e.ColumnIndex].Name.ToString(); 9 string keyname = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); 10 string com = "select * from testtwo where ID = @keyname"; 11 //OleDbParameter head1 = new OleDbParameter(@headname, headname); 12 DataSet rea = Sdatareader.dsmethod(com, new OleDbParameter(@keyname, keyname)); 13 DataRow dr = rea.Tables[0].Rows[0]; 14 form4.textBox1.Text = dr[dataGridView1.Columns[e.ColumnIndex].Name.ToString()].ToString(); //dr[]中直接放入字段发现不能执行 15 form4.textBox2.Text = keyname; 16 form4.textBox3.Text = headname; 17 } 18 //获取每个单元格的行与列 19 //int i1 = e.ColumnIndex; 20 //int i2 = e.RowIndex; 21 //MessageBox.Show(string.Format("行{0},列{1}", i2, i1)); 22 }
获取行的ID并传给form4中的textbox
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public System.Windows.Forms.TextBox textBox3; //改动这里的private属性以便在form1中插入数据
将form4.designers.cs中进行修改方可传值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 private void button1_Click(object sender, EventArgs e) 2 { 3 string headname = textBox3.Text.Trim(); 4 string text = textBox1.Text.Trim(); 5 string realdt = textBox2.Text.Trim(); 6 //string com = "UPDATE textno1 SET "+headname+" = "+text+" WHERE phone = "; 7 string com = "UPDATE testtwo SET " + headname + " =@text WHERE ID =@realdt ";//一开始主键设置为日期后字段名字符串化,参数化均报错,如至少一个参数没有指定等~~ 8 //string com1 = com + realdt; 9 //string com = "UPDATE textno1 SET '"+@headname+ "'= '"+@text+ " WHERE realdatetime = "+@realdt+""; 10 //Sdatareader.enqmethod(com1); 11 //Sdatareader.enqmethod(com,new OleDbParameter(@headname,headname),new OleDbParameter(@text,text),new OleDbParameter(@realdt,realdt)); 12 Sdatareader.enqmethod(com, new OleDbParameter(@text, text), new OleDbParameter(@realdt, realdt)); 13 MessageBox.Show("OK"); 14 }
form4中的按钮用于进行更改功能