private void btnSave_Click(object sender, EventArgs e) { DataTable sourseTable = (DataTable)this.GridViewStudent.DataSource; objStudentDetails oStudent = new objStudentDetails(); clsStudentDetails cStudent = new clsStudentDetails(); if (sourseTable.Rows.Count > 0) { for (int i = 0; i < sourseTable.Rows.Count; i++) { oStudent.StudentId = sourseTable.Rows[i]["Student Id"].ToString(); oStudent.Name = sourseTable.Rows[i]["Name"].ToString(); oStudent.dob = sourseTable.Rows[i]["Date Of Birth"].ToString(); oStudent.gradePoint = Convert.ToDecimal(sourseTable.Rows[i]["GradePointAvg"]); oStudent.status = Convert.ToBoolean(sourseTable.Rows[i]["Active"]); cStudent.InsertRecord(oStudent); MessageBox.Show("Successfully Inserted", Resource1.Customer_Name.ToString()); this.GridViewStudent.DataSource = CreateTable(); } } else { MessageBox.Show("Please Enter Student Details and Try to Save", Resource1.Customer_Name.ToString()); } }
public void InsertRecord(objStudentDetails oStudent) { try { SqlParameter param = new SqlParameter(); List<SqlParameter> paramList = new List<SqlParameter>(); param = SqlHelper.CreateParameter("@StudentId",SqlDbType.VarChar); param.Value = oStudent.StudentId.ToString(); paramList.Add(param); param = SqlHelper.CreateParameter("@StudentName", SqlDbType.VarChar); param.Value = oStudent.Name.ToString(); paramList.Add(param); param = SqlHelper.CreateParameter("@Dob", SqlDbType.DateTime); param.Value = Convert.ToDateTime(oStudent.dob); paramList.Add(param); param = SqlHelper.CreateParameter("@GradePoint", SqlDbType.Decimal); param.Value = oStudent.gradePoint; paramList.Add(param); param = SqlHelper.CreateParameter("@Status", SqlDbType.Bit); param.Value = oStudent.status; paramList.Add(param); SqlHelper.ExecuteNonQuery("sp_InsertStudentDetails", CommandType.StoredProcedure, paramList); } catch (Exception) { throw new System.NotImplementedException(); } }