使用Dev中的GridView进行数据增删操作

 
使用OracleHelper(一个C#操作Oracle数据库的工具类),连接的打开关闭全部交给OracleHelper去做。
进行增加数据信息时,新开增加数据信息的窗口,并且接受窗口的返回值,如果返回OK,对GridControl重新进行数据绑定。
1 AddForm1 add = new AddForm1();
2 if (add.ShowDialog() == DialogResult.OK)
3 {
4 this.gridControl1.DataSource = DataSource();
5 }
6  

 

在增加学生信息的窗口中,只需要调用OracleHelper中的方法将数据插入:
1  
2 int result = OracleHelper.ExecuteNonQuery(CommandType.Text,sqlStr);
3 DialogResult = DialogResult.OK;
4  
5 this.Close();

 

新开窗口填入信息——>窗口关闭前返回窗口返回值——>如果返回值为OK,重新绑定数据源
 
 
同样删除也是一样的道理
 
string status = this.gridViewStudent.GetRowCellValue(this.gridViewStudent.FocusedRowHandle, this.gridViewStudent.Columns["STU_ID"]).ToString();
string stuId = ((DataRow)((DataRowView)this.gridViewStudent.GetFocusedRow()).Row).ItemArray[0].ToString();
busSutdent.DelStudentData(Convert.ToInt32(stuId),ref errText);
this.gridViewStudent.DeleteSelectedRows();
MessageBox.Show("操作成功!", "系统提示");

 

 
调用OracleHelper进行数据删除之后,再调用DeleteSeletedRows()方法将数据在GridView控件中删除。
posted @ 2017-08-31 11:14  甲子湖畔是与非  阅读(708)  评论(0编辑  收藏  举报