Advertisement
Guest User

CustomerTable

a guest
Apr 25th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Oracle.ManagedDataAccess.Client;
  7. using PaymentClasses;
  8.  
  9.  
  10. namespace Databases
  11. {
  12. public class CustomerTable
  13. {
  14. private const string HOST = "calvin.humber.ca";
  15. private const string SID = "grok";
  16. internal const string PASSWORD = "oracle";
  17. private const string USER_ID = "N01317568";
  18.  
  19. private static readonly string strCONNECTIONSTRING = string.Format("DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" +
  20. "(HOST={0})(PORT=1521))(CONNECT_DATA=(SID={1}))); " +
  21. "PASSWORD={2}; USER ID={3}", HOST, SID, PASSWORD, USER_ID);
  22. private OracleConnection oracleConnection;
  23. private OracleCommand oracleCommand;
  24. private OracleDataReader oracleDataReader;
  25.  
  26. public CustomerTable()
  27. {
  28. try
  29. {
  30. oracleConnection = new OracleConnection(strCONNECTIONSTRING);
  31. oracleCommand = new OracleCommand();
  32. oracleCommand.Connection = oracleConnection;
  33. oracleConnection.Open();
  34. }
  35. catch (Exception objException)
  36. {
  37. throw objException;
  38. }
  39. }
  40.  
  41.  
  42.  
  43.  
  44. public Customer GetCustomer(string lname)
  45. {
  46. string strSQL = "SELECT * from customers Where LASTNAME = " + lname;
  47. Customer cust = new Customer();
  48. try
  49. {
  50. oracleCommand.CommandText = strSQL;
  51. oracleDataReader = oracleCommand.ExecuteReader();
  52. if (oracleDataReader.Read())
  53. {
  54. cust.FirstName = Convert.ToString(oracleDataReader["FIRSTNAME"]);
  55. cust.LastName = Convert.ToString(oracleDataReader["LASTNAME"]);
  56. cust.Address = Convert.ToString(oracleDataReader["ADDRESS"]);
  57. }
  58. else
  59. {
  60. Exception myException = new Exception("Sorry, that record id doesn't exist on the database");
  61. throw myException;
  62. }
  63. }
  64. catch (Exception objException)
  65. {
  66. throw objException;
  67. }
  68. return cust;
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement