public bool add_TemStudentData(studentBean st_Bean, SqlConnection sqlConn, SqlTransaction sqlTxn) { //Creating variable and objects SqlCommand sqlCmd = new SqlCommand(); bool status = false; try { //Calling the sp_InsertTempStudentData add temp table data sqlCmd = new SqlCommand("sp_InsertTempStudentData", sqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; //Assing Sql Transaction sql Command sqlCmd.Transaction = sqlTxn; //seting the parameter data types sqlCmd.Parameters.Add("@studentId", SqlDbType.Int); sqlCmd.Parameters.Add("@st_Name", SqlDbType.VarChar); sqlCmd.Parameters.Add("@st_DOB", SqlDbType.DateTime); sqlCmd.Parameters.Add("@st_GradePointAvg", SqlDbType.Decimal); sqlCmd.Parameters.Add("@st_Active", SqlDbType.VarChar); //Assing the values for parametters sqlCmd.Parameters["@studentId"].Value = st_Bean.Studentid; sqlCmd.Parameters["@st_Name"].Value = st_Bean.St_name; sqlCmd.Parameters["@st_DOB"].Value = st_Bean.Dob; sqlCmd.Parameters["@st_GradePointAvg"].Value = st_Bean.St_gradepointavg; sqlCmd.Parameters["@st_Active"].Value = st_Bean.St_active; sqlCmd.ExecuteNonQuery(); //Commit Transaction if there is no error occured sqlTxn.Commit(); //set the status to true status = true; } catch (SqlException ex) { //Rowllback if error orcured and throwing error next layer sqlTxn.Rollback(); throw ex; } finally { //disposing the conn object sqlcmd objects if (sqlConn != null) { sqlConn.Close(); } if (sqlCmd != null) { sqlCmd.Dispose(); } } //returnig the value return(status); }
public bool add_TemStudentData(studentBean st_Bean) { //Creating variable and objects bool status = false; SqlConnection sqlConn = null; SqlTransaction sqlTrn = null; dbConnection dbConn = null; studentDB stDB = null; try { //Inizing objects stDB = new studentDB(); dbConn = new dbConnection(); sqlConn = new SqlConnection(); //Inizing Sql Connection sqlConn = dbConn.getConnection(); //Connection Open sqlConn.Open(); //Transaction Beging sqlTrn = sqlConn.BeginTransaction(); //Assing the return valeu status = stDB.add_TemStudentData(st_Bean, sqlConn, sqlTrn); } catch (SqlException ex) { //throw exception to next layer throw ex; } finally { //disposing creating objects if (sqlConn != null) { sqlConn.Close(); } sqlTrn.Dispose(); } //returning tha value return(status); }
public bool add_TemStudentData(studentBean st_Bean) { bool status = true; //Assigning the values to struct array stu_Array[count].studentId = st_Bean.Studentid; stu_Array[count].st_Name = st_Bean.St_name; stu_Array[count].st_DOB = st_Bean.Dob; stu_Array[count].st_GradePointAvg = st_Bean.St_gradepointavg; stu_Array[count].st_Active = st_Bean.St_active; /* stu_Array[count].studentId = 10; * stu_Array[count].st_Name = "dfsgfg"; * stu_Array[count].st_DOB = DateTime.Now; * stu_Array[count].st_GradePointAvg = 2; * stu_Array[count].st_Active = "yes";*/ //Array count increment by 1 count = count + 1; //return status return(status); }
private void btnOK_Click(object sender, EventArgs e) { studentBean stBean = null; studentInfo stInfo = null; if (valid_control()) { try { stBean = new studentBean(); stInfo = new studentInfo(); stBean.Studentid = Int32.Parse(this.txtStudentId.Text.ToString().Trim()); stBean.St_name = this.txtStudentName.Text.Trim(); stBean.Dob = DateTime.Parse(this.dtpDOB.Text.Trim()); stBean.St_gradepointavg = Decimal.Parse(this.txtGradeAvg.Text.Trim()); if (this.cbTrue.Checked) { stBean.St_active = "Yes"; } else { stBean.St_active = "No"; } if (stInfo.add_TemStudentData(stBean)) { MessageBox.Show(systemMessage.TEMP_SAVE, systemMessage.MESSAGEBOXTITLE_SUCCESS, MessageBoxButtons.OK, MessageBoxIcon.Information); frmStuden_Details frm_Stdetail = new frmStuden_Details(); globleVeriables.STU_ID = globleVeriables.STU_ID - 1; frmMain frm_M = new frmMain(); frm_Stdetail.MdiParent = frm_M; frm_M.mainPanel.Controls.Clear(); frm_M.mainPanel.Controls.Add(frm_Stdetail); frm_M.mainPanel.Dock = DockStyle.Fill; frm_Stdetail.Show(); // Close form this.Dispose(); } else { MessageBox.Show(systemMessage.TEMP_INSERT, systemMessage.MESSAGEBOXTITLE, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { globleVeriables.STU_ID = globleVeriables.STU_ID - 1; if (ex.Message.Equals("Database Not Found!")) { MessageBox.Show(systemMessage.DATABASE_NOTFOUND, systemMessage.MESSAGEBOXTITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(systemMessage.TEMP_INSERT, systemMessage.MESSAGEBOXTITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } clear_Content(); setStudentId(); } }