Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data.SqlClient;
- using System.Data.Sql;
- using System.Data;
- namespace Cours_19_mars
- {
- class Program
- {
- static void Main(string[] args)
- {
- #region part1
- /*
- 1DataClasses1DataContext MyContext = new DataClasses1DataContext();
- var result = from cl in MyContext.Clients select cl;
- foreach (Client x in result)
- {
- System.Console.WriteLine(x.Nom + " " + x.Prenom);
- }
- result.ToList().ForEach(x => x.localite = "Bruxelles");
- Console.WriteLine("Client sélectionné");
- var cl = new Clients();
- cl.IdClient = Guild.NewGuid();
- cl.Nom = "Vantrimpon";
- cl.Prenom = "Jean";
- cl.localite = "Mons";
- var cl1 = new Clients
- {
- Nom = "Bardot",
- Prenom = "Brigitte",
- localite = "Marseille"
- };
- MyContext.Clients.InsertOnSubmit(cl1);
- MyContext.SubmitChanges();
- */
- #endregion
- DataSet MyClients = new DataSet();
- MyClients.Tables.Add("Client");
- string MyConStr = @"Data Source =DESKTOP-2MG1GM4\Benoit; Initial Catalog=Commerce; Persist Security Info=True;User ID =Sportlife;Password=dudu455000;";
- SqlConnection MyConnect = new SqlConnection(MyConStr);
- try
- {
- MyConnect.Open();
- if (MyConnect.State == System.Data.ConnectionState.Open)
- {
- Console.WriteLine("Connection ouverte");
- SqlCommand MyCommand = new SqlCommand();
- SqlCommand MyCommand2 = new SqlCommand();
- MyCommand.Connection = MyConnect;
- MyCommand2.Connection = MyConnect;
- MyCommand.CommandType = System.Data.CommandType.Text;
- MyCommand.CommandType = System.Data.CommandType.Text;
- MyCommand.CommandText = "select * from Client";
- SqlDataReader MyReader = MyCommand.ExecuteReader();
- MyCommand2.CommandText = "delete from Client where ID_Client='5'";
- //Mode connecté
- /*while (MyReader.Read())
- {
- Console.WriteLine(MyReader["Nom"].toString());
- }*/
- MyClients.Tables[0].Load(MyReader);
- }
- // MyConnect.Close();
- foreach (DataRow client in MyClients.Tables[0].Rows)
- {
- Console.WriteLine(client["ville"]);
- }
- MyConnect.Close();
- }
- catch(SqlException ex)
- {
- Console.WriteLine(ex.Message);
- }
- catch(Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- Console.ReadKey();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement