private void loadData() { //Data Load SqlConnection con = new SqlConnection(cs); con.Open(); string showQry = "SELECT*FROM SGHR.Employees"; cmd = new SqlCommand(showQry, con); dtDepart = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dtDepart); FVEmployee.DataSource = dtDepart.DefaultView; FVEmployee.DataBind(); con.Close(); }
protected void btnAddEmployee_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(cs); if (checkboxYes.Checked || checkboxNo.Checked) { con.Open(); string qry = "sp_AllCRUDEmployee"; SqlCommand cmd = new SqlCommand(qry, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@empid", SqlDbType.Int); cmd.Parameters.AddWithValue("@empfirstname", SqlDbType.VarChar).Value = txtEmpFirstName.Text; cmd.Parameters.AddWithValue("@emplastname", SqlDbType.VarChar).Value = txtEmpLastName.Text; cmd.Parameters.AddWithValue("@gender", SqlDbType.VarChar).Value = comboBoxGender.Text; cmd.Parameters.AddWithValue("@maritalstatus", SqlDbType.VarChar).Value = comboBoxMarital.Text; cmd.Parameters.AddWithValue("@cellphone", SqlDbType.VarChar).Value = txtEmpPhone.Text; cmd.Parameters.AddWithValue("@dob", SqlDbType.Date).Value = Convert.ToDateTime(txtDOB.Text); cmd.Parameters.AddWithValue("@email", SqlDbType.VarChar).Value = txtEmpEmail.Text; cmd.Parameters.AddWithValue("@bloodgroup", SqlDbType.VarChar).Value = CombEmpBloodGroup.Text; cmd.Parameters.AddWithValue("@address", SqlDbType.VarChar).Value = txtEmpAddress.Text; cmd.Parameters.AddWithValue("@joiningdate", SqlDbType.Date).Value = Convert.ToDateTime(txtEmpJoinDate.Text); cmd.Parameters.AddWithValue("@terminationdate", SqlDbType.Date).Value = Convert.ToDateTime(txtEmpTerDate.Text); //byte[] images = null; //FileStream stream = new FileStream(imageLocation, FileMode.Open, FileAccess.Read); //BinaryReader brs = new BinaryReader(stream); //images = brs.ReadBytes((int)stream.Length); if (picUpload.HasFile) { string fileExt = Path.GetExtension(picUpload.FileName); if (fileExt.ToLower() != ".png" && fileExt.ToLower() != ".jpg" && fileExt.ToLower() != ".jpeg") { lblMess.Text = "Only files with .jpg , .jpeg and .png extension are allowed"; } else { int filesize = picUpload.PostedFile.ContentLength; if (filesize > 2097152) { lblMess.Text = "File size cannot be greater than 2 MB"; } else { picUpload.SaveAs(Server.MapPath("~/Images/" + picUpload.FileName)); } } } cmd.Parameters.AddWithValue("@emimage", picUpload.FileName.ToString()); cmd.Parameters.AddWithValue("@deptid", SqlDbType.Int).Value = comboBoxDept.SelectedValue.ToString(); cmd.Parameters.AddWithValue("@designationid", SqlDbType.Int).Value = comboBoxDes.SelectedValue.ToString(); cmd.Parameters.AddWithValue("@isactive", SqlDbType.Bit).Value = (Convert.ToInt32(active)); cmd.Parameters.AddWithValue("@operation", SqlDbType.VarChar).Value = "INSERT"; cmd.ExecuteNonQuery(); lblMess.Text = ("Record saved successfully!!!"); txtEmpAddress.Text = ""; CombEmpBloodGroup.Text = ""; txtEmpEmail.Text = ""; txtEmpFirstName.Text = ""; txtEmpLastName.Text = ""; txtEmpPhone.Text = ""; con.Close(); //Data Load con.Open(); string showQry = "SELECT*FROM SGHR.Employees"; cmd = new SqlCommand(showQry, con); dtDepart = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dtDepart); FVEmployee.DataSource = dtDepart.DefaultView; FVEmployee.DataBind(); con.Close(); } else { lblMess.Text = "Something Wrong"; } }