protected void btnsaveall_Click(object sender, EventArgs e) { transferhistory d = new transferhistory(); //d.TransferID = int.Parse(txttransferid.Text); d.EmpID = int.Parse(DRPemp.SelectedValue); d.OldDepartment = txtolddept.Text; //d.NewDepartment = txtnewdept.Text; d.OldDivision = txtolddiv.Text; //d.NewDivision = txtnewdev.Text; d.OldSection = txtoldsec.Text; //d.NewSection = txtnewsec.Text; d.TransferActiveDate = DateTime.Parse(Calendar1.SelectedDate.ToString()); d.TransferDate = DateTime.Parse(Calendar2.SelectedDate.ToString()); d.Remark = txtremark.Text; d.StatusState = txtstatusstate.Text; GridView1.DataSourceID = SqlDataSource1.ID; if (new transferAccess().insert(d) > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Suceesfully saved')", true); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Suceesfully saved')", true); } }
public int insert(transferhistory type) { var result = 0; string constr = ConfigurationManager.ConnectionStrings["hrm"].ConnectionString; con = new SqlConnection(constr); string sql = string.Format("Insert into Transfer_info(EmpID,OldDepartment,NewDepartment,OldDivision, NewDivision,OldSection,NewSection,TransferActiveDate,TransferDate,Remark,StatusState) values ({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')" , type.EmpID, type.OldDepartment, type.NewDepartment, type.OldDivision, type.NewDivision, type.OldSection, type.NewSection, type.TransferActiveDate, type.TransferDate, type.Remark, type.StatusState); cmd = new SqlCommand(sql, con); con.Open(); result = cmd.ExecuteNonQuery(); con.Close(); return(result); }