Guest User

Untitled

a guest
Nov 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. public bool GetDeptData(SqlConnection Conn, string StartDate,string EndDate, out DataTable DTDepartmentData)
  2. {
  3. SqlDataAdapter adapter = null;
  4. SqlCommand cmd = null;
  5. DateTime startDate = new DateTime();
  6. DateTime endDate = new DateTime();
  7. SqlDbType DepartmentID = new SqlDbType();
  8. DTDepartmentData = new DataTable();
  9.  
  10.  
  11.  
  12. try
  13. {
  14. // Set our start date and end date for last month
  15. startDate = DateTime.Parse(
  16. DateTime.Now.AddMonths(-1).Year.ToString() + "-" +
  17. DateTime.Now.AddMonths(-1).Month.ToString() + "-01 00:00:00");
  18. endDate = DateTime.Parse(
  19. DateTime.Now.AddMonths(-1).Year.ToString() + "-" +
  20. DateTime.Now.AddMonths(-1).Month.ToString() + "-" +
  21. DateTime.DaysInMonth(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month) + " 23:59:59");
  22.  
  23.  
  24.  
  25. // Call our stored procedure and populate the datatable with the Dept data
  26. adapter = new SqlDataAdapter();
  27. cmd = new SqlCommand("sp_EXAMPLESP", Conn);
  28. cmd.CommandType = CommandType.StoredProcedure;
  29. cmd.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = startDate;
  30. cmd.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = endDate;
  31. cmd.Parameters.Add("@DepartmentID", SqlDbType.VarChar).Value = "departmentID";
  32. adapter.SelectCommand = cmd;
  33. adapter.Fill(DTDepartmentData);
  34.  
  35. return true;
  36. }
  37. catch (Exception CaughtError)
  38. {
  39. this.ErrorMsg = "An error occurred in the GetDeptData method: " + CaughtError.ToString() + " || " + Environment.NewLine;
  40. return false;
  41. }
Add Comment
Please, Sign In to add comment