473,902 Members | 3,399 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 9967
Joe Campanini
58 New Member
Oops! Is my face red. You are right. How did you know that? How did I miss that?????? Thank you. I am forever in your debt.
Cap in hand, one last question, I promise I will try not to bother you again, how do I request a partial name i.e. Smith and get Smithsonian, Smith and Western as well as Smith.


PS How did you learn all this LINQ stuff Arie, where can I get the info, so I don't have to keep bothering you? I feel very embarrassed with this one sided arrangement, I wish there was something I could do for you to even the score, but my expertise is all with RPG III and SSL, and these are now defunct. I tried the MSDN web site but they do assume one already has a great deal of expertise, it's more of a reference site than learning from basics, and it is not so easy to read.
Nov 28 '11 #21
64 New Member
I often make this error myself, so I know the error message by heart :)

To check if a string contains something (I didn't check if it works, though, but it should):
Expand|Select|Wrap|Line Numbers
  1.     var q1 = from d in mdc.data
  2.     where d.surName.Contains("Smith")
  3.     select d;
And when I want to know something, I don't use tutorials or books, I just ask Google a question :) For example I didn't know the exact syntax that may be used to check if string contains something, so I asked The Mighty Google: "c# linq string contain" and checked few first results :) I usually do it like that, and then try something over and over, from different sides, using different approaches, until I get it right. I think learning on your own mistakes is the most efficient approach, because what you learned that way tends to stick with you.

And I usually assume that if I have a problem, then at least 1000 people in the world had the same or similar problem, and 100 of them shared it on the Internet, and then 10 of them found the solution (which I can shamesly copy :)).
Nov 28 '11 #22
Joe Campanini
58 New Member
Thanks Arie, I don't feel quite so bad now :)).
Nov 28 '11 #23
1,501 Recognized Expert Top Contributor
Hey guys, just a quick heads up. This runs together a bit in general, it's preferred to keep separate questions in separate threads. This is just more for searching ease... someone with a similar problem may come looking here for help and find your thread, but if a thread contains several different questions it makes it harder for the search engine to find it, and for people to sift through and find answers.

I'm not saying this thread is bad, per se, just keep this in mind for the future :)
Nov 28 '11 #24

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: 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: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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: 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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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.