Advertisement
Guest User

Untitled

a guest
May 27th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. //EXTRACTION DES PRODUITS LIST
  2.         private List<Product> RetrieveProducts()
  3.         {
  4.             //Connection
  5.             bool connected = false;
  6.  
  7.             string accessConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Password={1};", textBoxAccessPath.Text, textBoxAccessPassword.Text);
  8.  
  9.             OleDbConnection con;
  10.             con = new OleDbConnection(accessConnectionString);
  11.  
  12.             if (con.State != ConnectionState.Open)
  13.             {
  14.                 try
  15.                 {
  16.                     con.Open();
  17.                     connected = true;
  18.                 }
  19.                 catch (Exception exception)
  20.                 {
  21.  
  22.                 }
  23.             }
  24.  
  25.             //Retrive Data to create a temp array of current database
  26.             List<Product> productList = new List<Product>();
  27.  
  28.             OleDbCommand custCMD = new OleDbCommand("SELECT * FROM Prod", con);
  29.             OleDbDataReader custReader = custCMD.ExecuteReader();
  30.  
  31.             while (custReader.Read())
  32.             {
  33.  
  34.                 //Retrive Data to create a temp array of current database
  35.                 productList.Add(
  36.  
  37.                     new Product()
  38.                     {
  39.                         ProductUPC = custReader["ProdNumUPC"].ToString(),
  40.                         ProductName = custReader["PName"].ToString(),
  41.                         Price = custReader["PPrice2"].ToString(),
  42.                         Dispo = custReader["Addi4"].ToString()
  43.                     }
  44.                     );
  45.  
  46.                 Application.DoEvents();
  47.             }
  48.             return productList;
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement