//新增
DataRowView drv = myDataView.AddNew();//定義欲編輯的Row
DataRowView drv = myDataView[0];
如何使用新增資料
//1.建立DataView
myDataView = new DataView(myDataTable);
//myDataView = new DataView(myDataTable, "", "", DataViewRowState.CurrentRows);
//2.開始新增DataView
DataRowView drv = myDataView.AddNew();
drv["EmployeeID"] = this.myDataTable.Rows.Count + 1;
drv["Title"] = this.textBox1.Text;
drv["City"] = this.textBox2.Text;
//3.結束編輯DataView
drv.EndEdit();
//Binding
this.dataGridView1.DataSource = myDataView;
如何使用編輯資料
//1.建立DataView
myDataView = new DataView(myDataTable);
//myDataView = new DataView(myDataTable, "", "", DataViewRowState.CurrentRows);
//2.定義欲編輯的Row
DataRowView drv = myDataView[Convert.ToInt16(textBox3.Text) - 1];
//3.開始修改DataView
drv.BeginEdit();
drv[this.comboBox1.Text] = textBox4.Text;
//4.結束編輯DataView
drv.EndEdit();
this.dataGridView1.DataSource = myDataView;
如何使用刪除資料
//1.建立DataView
myDataView = new DataView(myDataTable);
//myDataView = new DataView(myDataTable, "", "", DataViewRowState.CurrentRows);
//2.定義欲編輯的Row
DataRowView drv = myDataView[Convert.ToInt16(this.textBox5.Text) - 1];
//3.開始修改DataView
drv.BeginEdit();
drv.Delete();
//4.結束編輯DataView
drv.EndEdit();
this.dataGridView1.DataSource = myDataView;
範例下載
沒有留言:
張貼留言