Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I set the ItemSource in DbConnect.cs as follows:
- //=====================================================================
- public class PlotList
- {
- public string Id { get; set; }
- public string PlotId { get; set; }
- public string Jobs { get; set; }
- public string Bids { get; set; }
- }
- public List<PlotList> SelectPlotLists()
- {
- string query = "SELECT plot_id, postcode, jobs, bid from plot WHERE postcode ='" + Plot + "'";
- // Create a list to store the result
- var plotList = new List<PlotList>();
- // Create command
- var cmd = new MySqlCommand(query, _connection);
- MySqlDataReader dataReader = cmd.ExecuteReader();
- // Read the data and store it in a list
- while (dataReader.Read())
- {
- var item = new PlotList();
- item.PlotId = dataReader["plot_id"] + "";
- item.Jobs = dataReader["jobs"] + "";
- item.Bids = dataReader["bid"] + "";
- plotList.Add(item);
- }
- // Close
- dataReader.Close();
- // Return list
- return plotList;
- }
- // I then set up the following method in MainWindow.xaml.cs and call it in MainWindow():
- //=====================================================================
- public void ResetPlot()
- {
- // Establish MySQL connection
- var dbObject = new DbConnect();
- dbObject.OpenConnection();
- // Fill plot list view
- List<DbConnect.PlotList> plotList = dbObject.SelectPlotLists();
- Dispatcher.BeginInvoke(
- new ThreadStart(() => PlotListView.ItemsSource = plotList));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement