Closed Thread
Results 1 to 6 of 6

Thread: web app with linq to sql

  1. #1
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question web app with linq to sql

    Hello,

    I am trying to do a simple thing, which is get the table from sql using linq and import it to listview, its just the same as my other one previously that i made with windows app but this time i am using wpf/html with C#, so mainly using wpf for gui, and C# for coding, the problem is, its a little different, for example, i try and group all the info together using listviewitem, but when i use that, i dont get the same properties, for example when i do in windows form:
    Code:
    listviewitem lv = new listviewitem();
    lv.Text = blah blah;
    lv.subitem.add(more blah);
    this works fine above, however for wpf or xaml, it doesnt when i try to do listviewitem, then do lv.teee.... wheres the TEXT!!!?? nothing, with my code that i attached (actaully i attached the entire project) includnig the sql database and error picture i get (screen shot), hope that helps, but again this is just to populate the listview with all the data in the sql database table, but having trouble with wpf, let me know if this makes sense to everyone

    Thanks in advance, i will try and figureitout on my part as well

    also i will be writing a tutorial onthe other stuff with windows apps, but since this is my birthday today, i will be busy this weekend
    Attached Thumbnails Attached Thumbnails web app with linq to sql-error.jpg  
    Attached Files Attached Files
    Its only funny till someone gets hurt.... THEN ITS HILARIOUS

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Mar 2009
    Posts
    1,375
    Rep Power
    24

    Re: web app with linq to sql

    I am a bit lost. Well, at first sight I noticed you are trying to display a HashSet within Listview items. I am not sure is this even possible. But we have a bigger problem...

    Code:
    HashSet<usergroup> group = new HashSet<usergroup>();
    ///...
    group.Add(users);
    Listview1.Items.Add(group);
    I started to comment in/out parts of the code, until I found the line that causes the exception. It is the foreach loop. Code below does not work, but disabling foreach does the trick.

    Code:
    foreach (var peeps in queryResults)
    {
        //usergroup users = new usergroup(peeps.FirstN, peeps.LastN, peeps.JobT);
        ////users.firstname = peeps.FirstN;
        ////users.lastname = peeps.LastN;
        ////users.jobtitle = peeps.JobT;
    
        //group.Add(users);
        //Listview1.Items.Add(group);
        //Listview1.Items.Add(peeps.FirstN.ToString());
    
        ////lv.Text = peeps.FirstN;
        ////lv.SubItems.Add(peeps.LastN);
        ////lv.SubItems.Add(peeps.JobT);
        ////listView1.Items.Add(lv);
    }

  4. #3
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Re: web app with linq to sql

    Thanks Arek for the discovery, dang, never would have thought it would be the foreach loop, but thats a great tip which i should have done, process of elimination, just wondering what should i do then... any advice instead of using the foreach loop or dont use the hashset, if not, since i cant use listviewitem, what class should i use?
    Its only funny till someone gets hurt.... THEN ITS HILARIOUS

  5. #4
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question Re: web app with linq to sql

    Hello,

    Still trying to figure out how to get this wpf web app working, not sure why the foreach is not working... dont know, any ideas. here is the code that is no working
    Code:
    public void querytable()
            {
                var queryResults = from c in db.tblUsers
                                   select new { FirstN = c.First_Name, LastN = c.Last_Name, JobT = c.Job_Title };
                
                foreach (var u in queryResults)
                {
                    usergroup users = new usergroup(u.FirstN, u.LastN, u.JobT);
                    group1.Add(users);
                    Listview1.Items.Add(group1);
    
    
                }
                
            }
    Its only funny till someone gets hurt.... THEN ITS HILARIOUS

  6. #5
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question Re: web app with linq to sql

    ahhhh still cant get it, any other ideas, i tried bindinglist but that is no success, i know it has to be the foreach, but what else i could i use besides foreach to make this dumb thing work??

    here is the code with the bindinglist instead of list or other sorts:

    Code:
            tbluserDataContext db = new tbluserDataContext();
            BindingList<usergroup> group = new BindingList<usergroup>();
    
            public void querytable()
            {
                var queryResults = from c in db.tblUsers
                                   select new { FirstN = c.First_Name, LastN = c.Last_Name, JobT = c.Job_Title };
    
                foreach (var u in queryResults)
                {
                    usergroup users = new usergroup(u.FirstN, u.LastN, u.JobT);
                    group.Add(users);
                    Listview1.Items.Add(group);
    
                }
            }
    any ideas please i am open to getting this dumb wpf web app done and working

    thanks all i will still try and get this dumb thing working even if it takes me aaaalll weeekend but input and suggestions please or resolution would be great
    Its only funny till someone gets hurt.... THEN ITS HILARIOUS

  7. #6
    Join Date
    Mar 2009
    Posts
    1,375
    Rep Power
    24

    Re: web app with linq to sql

    Yare yare, this topic is a real nut to crack. Lets regroup our forces and thoughts. Objective A: Fix the foreach loop, or even replace it. If you need to replace the query above too, then do so. I just can't figure this out.

    I found Scott Gu's blog about LINQ, and took a query. Dunno if it works any better then current query, just a hint. Maybe make a query like this, and then try foreach?

    Attached Thumbnails Attached Thumbnails web app with linq to sql-sshot-3.jpg  

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. LINQ
    By Tonchi in forum C# Programming
    Replies: 1
    Last Post: 08-20-2011, 01:54 PM
  2. Intermediate c# linq with strings
    By chili5 in forum CSharp Tutorials
    Replies: 0
    Last Post: 08-20-2011, 08:44 AM
  3. Help... It's linq to Sql
    By Tonaldex in forum C# Programming
    Replies: 4
    Last Post: 06-08-2011, 08:07 PM
  4. ASP.NET MVC & Linq
    By Shaddix in forum ASP, ASP.NET and Coldfusion
    Replies: 0
    Last Post: 05-11-2010, 12:54 AM
  5. C# linq to SQL
    By Siten0308 in forum C# Programming
    Replies: 16
    Last Post: 09-07-2009, 02:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

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