private void btnGetBatch_Click(object sender, EventArgs e) { Batch queryobject = new Batch(); if (!String.IsNullOrEmpty(txtBatchID.Text)) { queryobject.Batch_Id = int.Parse(txtBatchID.Text); } queryobject.Batchname = txtBatchName.Text; queryobject.Batchdescription = txtBatchDescription.Text; List<object> dataRet = queryobject.get(); List<Batch> data = new List<Batch>(); foreach (object o in dataRet) { data.Add(o as Batch); } var _bind = data.Select(a => new { Batch_id = a.Batch_Id, BatchName = a.Batchname, Batchdescription = a.Batchdescription, }).ToList(); batchGridView.DataSource = _bind; utility.AddDeleteAndEditButton(batchGridView); // Link for getting buttons working as part of grid. // http://stackoverflow.com/questions/10769316/add-a-button-in-a-new-column-to-all-rows-in-a-datagrid batchGridView.Update(); }
private void btnAddBatch_Click(object sender, EventArgs e) { // Create Object Batch newObj = new Batch(); newObj.Batchname = txtBatchName.Text; newObj.Batchdescription = txtBatchDescription.Text; // Assign read form's fields to object's fields // Call Save newObj.save(); // http://tech.pro/tutorial/776/csharp-tutorial-binding-a-datagridview-to-a-collection this.Close(); }
/// <summary> /// Object Specific function /// </summary> /// <param name="dr"></param> /// <returns></returns> public override object convertFromReader(OleDbDataReader dr) { Batch gotFromDB = new Batch(); gotFromDB.Batch_Id = int.Parse(dr[DatabaseCoachingInst.Batch.Batch_ID.ToString()].ToString()); gotFromDB.batchname = dr[DatabaseCoachingInst.Batch.BatchName.ToString()].ToString(); gotFromDB.Batchdescription = dr[DatabaseCoachingInst.Batch.BatchDescription.ToString()].ToString(); gotFromDB.class_id = int.Parse(dr[DatabaseCoachingInst.Batch.Class_ID.ToString()].ToString()); // write similar code for other fields. return gotFromDB; }