473,890 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LINQ to Entities and filling a DataGrid

58 New Member
I have asked this question previously and I had an answer that, while not exactly what I wanted and did not use a DataGridView, worked, so for that thanks Paul Johnson. However, I now need to get an answer that uses the DataGridView, since I would like to use all the cool features of the DataGridView, and also be more elegant.

The scenario is as follows... I wish to selectively read a number of records from a SQL database from a C# program using LINQ to Entities, e.g., everybody whose name is Smith. I now want to populate a DataGridView with all the "Smith's" data, i.e., first name, address details etc. Now because Smith is such a common name there could be dozens of records, and the DataGridView gives me the opportunity to scroll through the list and select the one I want.

I'm sure it can be done; I just don't know how...Anyone?
Sep 4 '11
23 9963
Joe Campanini
58 New Member
Arie, just wanted to thank you for all your help, my dataGridView window is looking so slick and in no small portion to your really, really helpful suggestions. So once again, thank you.

Nov 25 '11 #11
64 New Member
No problem :) I'm glad I could help
Nov 25 '11 #12
Joe Campanini
58 New Member
Hi Arie, you are probable going to think me a bit of a twit, but how do I clear out the dataGridView? When I do a second search, without leaving the program, the next set of data gets added to the end of the previous set of data, and so on, ad infinitum!!
Nov 25 '11 #13
64 New Member
Try doing this
Expand|Select|Wrap|Line Numbers
  1. CurrencyManager cm = (CurrencyManager)this.dataGridView1.BindingContext[myBindedDataSource];
  2. if (cm != null)
  3. {
  4.    cm.Refresh();
  5. }
after reloading your data source
Nov 25 '11 #14
Joe Campanini
58 New Member
Hey, I worked it out, set the bindingList to null!! Duh!!
Nov 25 '11 #15
Joe Campanini
58 New Member
Ah! Great minds think alike :-)
Nov 25 '11 #16
Joe Campanini
58 New Member
It's me again Arie. Sorry to trouble you again but I have a question that maybe you could answer. I want to expand my LINQ to SQL to include more than one "where". e.g. var q1 = from d in mdc.data
where d.surName == SurName and
where d.firstName == FirstName
select d;
Can it be done with one LINQ expression or do I do the one where and then do an "if" to include the second requirement? I've opted for the "if" solution but it doesn't look very elegant.

Nov 27 '11 #17
64 New Member
I think you can do:
Expand|Select|Wrap|Line Numbers
  1. var q1 = from d in mdc.data
  2.  where d.surName == SurName && d.firstName == FirstName
  3.  select d;
Nov 27 '11 #18
Joe Campanini
58 New Member
Sorry Arie, It doesn't like that, Err message - Operator '&&' cannot be applied to operands of type string and bool. I don't know if it makes any difference but SurName and FirstName are actually SurName.Text and FirstName.Text (input from a text box)! When I hover the cursor over them that both reflect type string, so I don't know where bool is coming from.
Nov 27 '11 #19
64 New Member
Are you ABSOLUTELY SURE that you didn't forget '=' character somwhere here?

If I do this:
Expand|Select|Wrap|Line Numbers
  1. var q1 = from d in mdc.data
  2. where d.surName = SurName && d.firstName == FirstName
  3. select d;
I get exactly the error message that you're getting
Nov 28 '11 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Krzysztof Karnicki | last post by:
I have such a problem… I have create my custom DataGridColumn inheriting from System.Windows.Forms.DataGridColumnStyle on using it on DataGrid, to show rows painted by me self. Because dates taken from database are very large, and filling DataSet bounded to this DataGrid takes some time, a decided to put fill logic into new thread. And so method running in this thread clears only this DataSet bounded to DataGrid and fills it once more...
by: Saket Mundra | last post by:
I have a Datagrid in which i want to dispaly only those rows that match the text specified by user in the text box.How do i do that ? How do i refresh the data in the Datagrid everytime the text is changed in the textbox. -- Thank You. Saket Mundra
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more proper tier to put it since is a data function But then I've heard that writing SQL in my client .NET code might run just as fast? Dynamic SQL or something? And then there's LINQ on the horizon. Is it a successor to everything
by: rangtara | last post by:
Hi, I want to fill the datagrid at runtime from sql server database. please give me help on this. thanks in advance
by: bebadgujar | last post by:
hi to all, i have data in large amount say like 500. now i have to show that data in grid. but in grid only 10 data shoul be displayed at a time. means i want 50 grid to disply fro 500 data. so is it possible to display all the data by fixing the rowlimit of grid.
by: paululvinius | last post by:
Hi! Testing som Linq-expressions and tried to measure performance and compare it to pre-Linq programming. The folloing two methods are functional equal but the non-Linq one is twice as fast. public List<ConferenceRoomOldWay(int minimumSeatingCapacity) {
by: m.a | last post by:
Hello, I want to use LINQ and ms access. A quick googling showed me that I can not use LINQ with MS access as LINQ needs a an SQL server, Am I right?. I also found that if I wrote my own entities to map tables and ... into C# classes, then I can use LINQ to query database. Is there any more information about how I can write the entities for a
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and not reinsert it with a different revision number. Compounding the issue, we’ve also got an associated table storing properties for our entities which is not revisioned, but we still want changes to the children of our entity (additions, changes...
by: ck1 | last post by:
Hi at all - I want to know if there are diffirence with Liqn to SQL and Linq To entity performance. I have read many article on the web that say that Linq To Entity is more fast than Linq To Sql. What is your experience about that ? ck1;
by: James Folkerman | last post by:
Hi. I have SQL Server database that is connected to my WPF desktop-based application via ADO.NET Entity Framework. Now I need get content of one of the table via LINQ query and show it in DataGrid control. Also, I need to let user to edit or delete data from DataGrid and update my database according this change. Here is a LINQ query: from d in App.glidusContext.tbl_users select new { d.userID, d.userName, d.userPassword }
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.