Advertisement
Guest User

Untitled

a guest
Dec 10th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. // I set the ItemSource in DbConnect.cs as follows:
  2. //=====================================================================
  3.  
  4. public class PlotList
  5. {
  6.     public string Id { get; set; }
  7.     public string PlotId { get; set; }
  8.     public string Jobs { get; set; }
  9.     public string Bids { get; set; }
  10. }        
  11.  
  12. public List<PlotList> SelectPlotLists()
  13. {
  14.     string query = "SELECT plot_id, postcode, jobs, bid from plot WHERE postcode ='" + Plot + "'";
  15.    
  16.     // Create a list to store the result
  17.     var plotList = new List<PlotList>();
  18.    
  19.     // Create command
  20.     var cmd = new MySqlCommand(query, _connection);
  21.     MySqlDataReader dataReader = cmd.ExecuteReader();
  22.    
  23.     // Read the data and store it in a list
  24.     while (dataReader.Read())
  25.     {
  26.         var item = new PlotList();
  27.         item.PlotId = dataReader["plot_id"] + "";
  28.         item.Jobs = dataReader["jobs"] + "";
  29.         item.Bids = dataReader["bid"] + "";
  30.         plotList.Add(item);
  31.     }
  32.    
  33.     // Close
  34.     dataReader.Close();
  35.    
  36.     // Return list
  37.     return plotList;
  38. }
  39.  
  40. //  I then set up the following method in MainWindow.xaml.cs and call it in MainWindow():
  41. //=====================================================================
  42.  
  43. public void ResetPlot()
  44.         {
  45.             // Establish MySQL connection
  46.             var dbObject = new DbConnect();
  47.             dbObject.OpenConnection();
  48.  
  49.             // Fill plot list view
  50.             List<DbConnect.PlotList> plotList = dbObject.SelectPlotLists();
  51.             Dispatcher.BeginInvoke(
  52.                 new ThreadStart(() => PlotListView.ItemsSource = plotList));
  53.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement