Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool GetDeptData(SqlConnection Conn, string StartDate,string EndDate, out DataTable DTDepartmentData)
- {
- SqlDataAdapter adapter = null;
- SqlCommand cmd = null;
- DateTime startDate = new DateTime();
- DateTime endDate = new DateTime();
- SqlDbType DepartmentID = new SqlDbType();
- DTDepartmentData = new DataTable();
- try
- {
- // Set our start date and end date for last month
- startDate = DateTime.Parse(
- DateTime.Now.AddMonths(-1).Year.ToString() + "-" +
- DateTime.Now.AddMonths(-1).Month.ToString() + "-01 00:00:00");
- endDate = DateTime.Parse(
- DateTime.Now.AddMonths(-1).Year.ToString() + "-" +
- DateTime.Now.AddMonths(-1).Month.ToString() + "-" +
- DateTime.DaysInMonth(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month) + " 23:59:59");
- // Call our stored procedure and populate the datatable with the Dept data
- adapter = new SqlDataAdapter();
- cmd = new SqlCommand("sp_EXAMPLESP", Conn);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = startDate;
- cmd.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = endDate;
- cmd.Parameters.Add("@DepartmentID", SqlDbType.VarChar).Value = "departmentID";
- adapter.SelectCommand = cmd;
- adapter.Fill(DTDepartmentData);
- return true;
- }
- catch (Exception CaughtError)
- {
- this.ErrorMsg = "An error occurred in the GetDeptData method: " + CaughtError.ToString() + " || " + Environment.NewLine;
- return false;
- }
Add Comment
Please, Sign In to add comment