Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void btnUpdate_Click(object sender, EventArgs e)
        {
            char gen;

            #region feed Value

            _objEntityStudent.FirstName = txtFirstName.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.LastName = txtLastName.Text.ToString().Trim().Replace("'", "");
            if (rbGenderFemale.Checked)
            {
                gen = 'F';
            }
            else
            {
                gen = 'M';
            }
            _objEntityStudent.Gender = gen;
            _objEntityStudent.Email = txtEmail.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.Phone = txtPhone.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.Mobile = txtMobile.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.Address = txtAddress.Text.ToString().Trim().Replace("'", "");
            try
            {
                _objEntityStudent.DOB = Convert.ToDateTime(txtDOB.Text.ToString().Trim().Replace("'", ""));
            }
            catch (Exception ex)
            {
                lblError.Text = "Start Date not in proper format !";
                return;
            }
            _objEntityStudent.BloodGroup = txtBloodGroup.Text.ToString().Trim().Replace("'", "");
            try
            {
                _objEntityStudent.AdmissionDate = Convert.ToDateTime(txtAdmissionDate.Text.ToString().Trim().Replace("'", ""));
            }
            catch (Exception ex)
            {
                lblError.Text = "Admission Date not in proper format !";
                return;
            }

            _objEntityStudent.CityId = Convert.ToInt32(ddlCity.SelectedValue);
            _objEntityStudent.StateId = Convert.ToInt32(ddlState.SelectedValue);
            _objEntityStudent.Pincode = txtPincode.Text.ToString().Trim().Replace("'", "");

            _objEntityStudent.Theme = ddlTheme.SelectedValue;
            _objEntityStudent.Menu = ddlMenu.SelectedValue;

            _objEntityStudent.Description = txtDescription.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.InstituteName = txtInstituteName.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.ClassName = txtClassName.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.YearPassing = ddlYearPassing.SelectedItem.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.ObtainedMarks = txtObtaineMarks.Text.ToString().Trim().Replace("'", "");
            _objEntityStudent.IsActive = Convert.ToInt32(ddlActive.SelectedValue);

            _objEntityStudent.UpdatedBy = 0;
            _objEntityStudent.DeletedBy = 0;
            _objEntityStudent.IsDeleted = 0;
            #endregion

            _objEntityStudent.Mode = Mode.Update;
            _objEntityStudent.FirstName = this.txtFirstName.Text;
            _objEntityStudent.LastName = this.txtLastName.Text;
            _objEntityStudent.StudentId = Convert.ToInt32(Session["LoginId"].ToString());
            _objEntityStudent.CustomerId = Convert.ToInt32(Session["CustomerId"].ToString());
            _objEntityStudent.UpdatedBy = Convert.ToInt32(Session["CustomerId"].ToString());
            // StudentId = 2;
            StudentId = _objIBALStudent.UpdateStudent(_objEntityStudent);

            if (StudentId == 0)
            {
                lblError.ForeColor = Color.Red;
                lblError.Text = "<img src='images/alert.png' alt='' /> Error in Student data updation";
            }
            else
            {
                if (_strError.Length == 0)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "alert('Student Updated Successfully !'); document.location.href='SelfProfile.aspx'; ", true);
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "alert('" + _strError + "'); ", true);
                }
            }

            pnlEdit.Visible = false; pnlView.Visible = true;
        }
    }
}

C#
//In BAL
   #region UpdateStudent
        public Int64 UpdateStudent(EntityStudent objEntityStudent)
        {
            return _objDalSqlServer.UpdateStudent(objEntityStudent);
        }
        #endregion


C#
//In DAL
 #region Update Student Batch Detail
                Int32 StudentId = Convert.ToInt32(_objSqlParameter[33].Value.ToString());
               string[] arrayBatchIds = objEntityStudent.BatchIds.Split(',');
                string strSql = "";                
strSql = " Delete StudentBatchMapping Where CustomerId=" + objEntityStudent.CustomerId;
                strSql += "  and StudentId=" + objEntityStudent.StudentId;
                SqlHelper.ExecuteNonQuery(_objSqlConnection, CommandType.Text, strSql);

                for (int i = 0; i < arrayBatchIds.Length; i++)
                {
                    strSql = " Insert Into StudentBatchMapping (CustomerId,StudentId,BatchId) Values (";
                    strSql += objEntityStudent.CustomerId + "," + objEntityStudent.StudentId + "," + arrayBatchIds[i].ToString() + ")";
                    SqlHelper.ExecuteNonQuery(_objSqlConnection, CommandType.Text, strSql);
                }
                #endregion

                return StudentId;
            }
            catch (Exception ex)
            {
                //System.Diagnostics.Trace.TraceError("Error : Company Name - {0} :: DalSqlAzure : UpdateUser : {1} ", HttpContext.Current.Session["CompanyName"].ToString(), ex.Message);
                return 0;
            }
            finally
            {
                _objSqlConnection.Close();
                _objSqlConnection.Dispose();
            }
        }
        #endregion
Posted
Updated 4-Nov-12 16:57pm
v2
Comments
_Amy 4-Nov-12 23:32pm    
Where is @ImagePath in your code? I am not able to find that.. This may be issue of database.
OriginalGriff 5-Nov-12 2:24am    
You need to show us the line that is throwing the exception, and a small number of lines around it for context - you aren't doing that as @ImagePath is not in the code fragment you give.
Use the "Improve question" widget to edit your question and provide better information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900