Results 1 to 4 of 4

Thread: LINQ to SQL (EDMX Model) get column names and value from single row in DB

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2001
    Location
    VA, USA
    Posts
    36

    Unhappy LINQ to SQL (EDMX Model) get column names and value from single row in DB

    I have an app i'm developing, Each record is singular and unique in the DB, there will only ever be a couple dozen records (not that this matters)

    i am trying to get the column name and the value to display in a listbox on the form (winforms c#, 4.5.2)

    Code:
                var doc = cboPhysician.Items[cboPhysician.SelectedIndex] as pItem;
                var rec = (from a in db.DOCCREDs where a.DOC == doc.EEID select a).ToList();
    
                var fields = typeof(DOCCRED).GetFields();
                foreach(var it in rec)
                {
                    foreach(var f in fields)
                    {
                        string s;
                        s = f.Name + ':' + f.GetValue(it);
                        lbxDocDetails.Items.Add(s);
                    }
                }
    is what i have so far, its bombing out in the inner foreach loop, so its like its not loading the table structure. Stolen off the stack, so no guarantees its worthy of time etc. but all assistance appreciated.
    second place is just the first loser...

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: LINQ to SQL (EDMX Model) get column names and value from single row in DB

    Firstly, is there a specific reason that you're using 'cboPhysician.Items[cboPhysician.SelectedIndex]' instead of 'cboPhysician.SelectedItem'?

    Secondly, what exactly does "bombing out" mean? Presumably there's an exception thrown so there's an exception message. What is it?

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2001
    Location
    VA, USA
    Posts
    36

    Re: LINQ to SQL (EDMX Model) get column names and value from single row in DB

    1stly, force of habit, its a custom item class that i use to load string/string instead of int/string like you normallly would. all it does is get the key from the combobox and use it to look up the doc.

    2ndly, no error is being tossed, i get a 0 length in break (like the table does not exist or have data in it) its nothing but a table of dates

    so output should be

    PW:04/01/2019
    Act:04/30/2019
    AMA:04/30/2018

    FieldName:value

    etc. I can just reload the date pickers with the data easy enough, but thought this might be a easier on the user type of thing to put it in a list box, and i get to learn something new in the process.
    second place is just the first loser...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: LINQ to SQL (EDMX Model) get column names and value from single row in DB

    Quote Originally Posted by dirty_howi View Post
    2ndly, no error is being tossed, i get a 0 length in break (like the table does not exist or have data in it) its nothing but a table of dates
    I don't understand what that means. Please provide a FULL and CLEAR explanation of the problem. Tell us exactly what you expect to happen and exactly what does happen. Have you stepped through the code? If not, you should do so. If you have, where exactly does execution vary from what you expect and exactly how?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width