Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. static void Insertexample()
  2. // inserts a new record in workplace
  3. {
  4.  
  5. string cprstring;
  6. string companystring;
  7. Console.WriteLine("Indtast cpr-number");
  8. cprstring = Console.ReadLine();
  9. Console.WriteLine("Indtast company-number");
  10. companystring = Console.ReadLine();
  11.  
  12. string sql;
  13. sql = "insert into workplace values ('"+ cprstring + "'," + companystring + ")";
  14. //OracleCommand cmd = new OracleCommand();
  15.  
  16. DbCommand cmd = dbFactory.CreateCommand();
  17. cmd.Connection = con;
  18. cmd.CommandText = sql;
  19.  
  20. // lćs tabellen person
  21. try
  22. { // ĺbn forbindelse til database
  23. con.Open();
  24. cmd.ExecuteNonQuery();
  25. Console.WriteLine("The insert is done");
  26. }
  27. catch (OracleException ex)
  28. {
  29.  
  30. if (ex.Message.Contains("ORA-02291: integrity constraint (SYSTEM.CPRFOREIGN)"))
  31. Console.WriteLine("The cpr number does not exits");
  32. if (ex.Message.Contains("ORA-02291: integrity constraint (SYSTEM.COMPANYFOREIGN)"))
  33. Console.WriteLine("The company number does not exits");
  34. if(ex.Message.Contains("ORA-00001"))
  35. Console.WriteLine("Person already exists in company");
  36.  
  37. }
  38.  
  39. finally
  40. { // luk forbindelse til databasen
  41. con.Close();
  42. }
  43.  
  44. Console.WriteLine();
  45. Console.WriteLine("---------------------------------------------------------------------");
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement