Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. LINQ Scope Question

LINQ Scope Question

Scheduled Pinned Locked Moved LINQ
tutorialdatabasequestioncsharplinq
2 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hypermommy
    wrote on last edited by
    #1

    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
    
    H 1 Reply Last reply
    0
    • H Hypermommy

      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
      
      H Offline
      H Offline
      Hypermommy
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups