Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 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 System.Data.SqlClient;
  7. using System.Data.Sql;
  8. using System.Data;
  9.  
  10. namespace Cours_19_mars
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. #region part1
  17. /*
  18. 1DataClasses1DataContext MyContext = new DataClasses1DataContext();
  19. var result = from cl in MyContext.Clients select cl;
  20. foreach (Client x in result)
  21. {
  22. System.Console.WriteLine(x.Nom + " " + x.Prenom);
  23. }
  24. result.ToList().ForEach(x => x.localite = "Bruxelles");
  25. Console.WriteLine("Client sélectionné");
  26. var cl = new Clients();
  27. cl.IdClient = Guild.NewGuid();
  28. cl.Nom = "Vantrimpon";
  29. cl.Prenom = "Jean";
  30. cl.localite = "Mons";
  31.  
  32. var cl1 = new Clients
  33. {
  34. Nom = "Bardot",
  35. Prenom = "Brigitte",
  36. localite = "Marseille"
  37. };
  38.  
  39. MyContext.Clients.InsertOnSubmit(cl1);
  40.  
  41. MyContext.SubmitChanges();
  42. */
  43. #endregion
  44. DataSet MyClients = new DataSet();
  45. MyClients.Tables.Add("Client");
  46. string MyConStr = @"Data Source =DESKTOP-2MG1GM4\Benoit; Initial Catalog=Commerce; Persist Security Info=True;User ID =Sportlife;Password=dudu455000;";
  47. SqlConnection MyConnect = new SqlConnection(MyConStr);
  48. try
  49. {
  50. MyConnect.Open();
  51. if (MyConnect.State == System.Data.ConnectionState.Open)
  52. {
  53. Console.WriteLine("Connection ouverte");
  54. SqlCommand MyCommand = new SqlCommand();
  55. SqlCommand MyCommand2 = new SqlCommand();
  56. MyCommand.Connection = MyConnect;
  57. MyCommand2.Connection = MyConnect;
  58. MyCommand.CommandType = System.Data.CommandType.Text;
  59. MyCommand.CommandType = System.Data.CommandType.Text;
  60.  
  61. MyCommand.CommandText = "select * from Client";
  62. SqlDataReader MyReader = MyCommand.ExecuteReader();
  63.  
  64. MyCommand2.CommandText = "delete from Client where ID_Client='5'";
  65. //Mode connecté
  66.  
  67. /*while (MyReader.Read())
  68. {
  69. Console.WriteLine(MyReader["Nom"].toString());
  70. }*/
  71. MyClients.Tables[0].Load(MyReader);
  72.  
  73. }
  74. // MyConnect.Close();
  75. foreach (DataRow client in MyClients.Tables[0].Rows)
  76. {
  77. Console.WriteLine(client["ville"]);
  78. }
  79. MyConnect.Close();
  80.  
  81. }
  82. catch(SqlException ex)
  83. {
  84. Console.WriteLine(ex.Message);
  85. }
  86. catch(Exception ex)
  87. {
  88. Console.WriteLine(ex.Message);
  89. }
  90. Console.ReadKey();
  91.  
  92. Console.ReadKey();
  93.  
  94. }
  95.  
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement