LINQ Scope Question
-
Hi all, I'm trying to learn how to use LINQ and I'm a bit confused over how I should do something so I'm hoping y'all can help. I have this form and basically the user selects something from the first two dropdowns and these selections determine what's shown in the cboActivity dropdown. Once the user populates the cboActivity dropdown (or changes the selected item) I fill in some text boxes with more detailed info about the activity. I also have a btnSaveChanges so the user can make modifications to the detailed info about the activity and save the changes back to the database. From what I'm understanding, LINQ will help keep track of what's changed and update the database appropriately. But I'm not sure if it'll do that given that I pull the data and populate the textboxes in the OnActivitySelectionChanged routine (which is a delegate called when the cboActivity dropdown is loaded or the selected item changed). I'm thinking I need to define something more at the form level so it can see the changes to the activity details and update the database, but I'm getting a bit confused on the reading I'm doing. Could someone help me understand how I need to arrange these objects? Or point me towards a relevant example/tutorial? I've included the code below. Thanks!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace SWM_Admin
{
public partial class frmByActivity : Form
{
dmSWMDataContext db = new dmSWMDataContext();public frmByActivity() { InitializeComponent(); // Initialize the Location Type dropdown LoadLocTypes(); } private void LoadLocTypes() { var dsLocTypes = (from a in db.lu\_locationtypes orderby a.Description select new { a.id, a.Description }).ToList(); dsLocTypes.Insert(0, new { id = 0, Description = "Select Location Type..." }); cboLocationType.DisplayMember = "Description"; cboLocationType.ValueMember = "id"; cboLocationType.DataSource = dsLocTypes; cboLocationType.SelectedValueChanged += new EventHandler(OnLocationTypeSelectionChanged); } private void GetLocations(Int32 LocType) { // Remove the event handler so it doesn't fire whe
-
Hi all, I'm trying to learn how to use LINQ and I'm a bit confused over how I should do something so I'm hoping y'all can help. I have this form and basically the user selects something from the first two dropdowns and these selections determine what's shown in the cboActivity dropdown. Once the user populates the cboActivity dropdown (or changes the selected item) I fill in some text boxes with more detailed info about the activity. I also have a btnSaveChanges so the user can make modifications to the detailed info about the activity and save the changes back to the database. From what I'm understanding, LINQ will help keep track of what's changed and update the database appropriately. But I'm not sure if it'll do that given that I pull the data and populate the textboxes in the OnActivitySelectionChanged routine (which is a delegate called when the cboActivity dropdown is loaded or the selected item changed). I'm thinking I need to define something more at the form level so it can see the changes to the activity details and update the database, but I'm getting a bit confused on the reading I'm doing. Could someone help me understand how I need to arrange these objects? Or point me towards a relevant example/tutorial? I've included the code below. Thanks!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace SWM_Admin
{
public partial class frmByActivity : Form
{
dmSWMDataContext db = new dmSWMDataContext();public frmByActivity() { InitializeComponent(); // Initialize the Location Type dropdown LoadLocTypes(); } private void LoadLocTypes() { var dsLocTypes = (from a in db.lu\_locationtypes orderby a.Description select new { a.id, a.Description }).ToList(); dsLocTypes.Insert(0, new { id = 0, Description = "Select Location Type..." }); cboLocationType.DisplayMember = "Description"; cboLocationType.ValueMember = "id"; cboLocationType.DataSource = dsLocTypes; cboLocationType.SelectedValueChanged += new EventHandler(OnLocationTypeSelectionChanged); } private void GetLocations(Int32 LocType) { // Remove the event handler so it doesn't fire whe
I think I may have found the info I need. I'm partway through reading this article but it's starting to make some sense now. The article is Simple LINQ to SQL in C#[^] just in case someone else faces the same issue.
Denise "Hypermommy" Duggan