.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Simple question.... LINQ on Datatable

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :ASP.Net
Hi all,Simple one this I am sure for those who use LINQ! :)I basically have two tables that will be stored in viewstate until I save the data to the database.  I need a way to query the datatables, delete remove etc.  Is this possible in LINQ?So for example, delete/select rows from the DataTable that have a particular ID etc...Thanks,Mark

View Complete Post

More Related Resource Links

Simple LINQ to SQL question


Someone help me with what I'm missing here...

I have a VERY simple file as you can see... just three tables.


The Problem is that if I do this somethign like this....

var patients = from x in db.CT_Patients
                     where x.CT_Visits...... (error here)


It doesn't display child properties for CT_Visits from CT_Patient like it should. I only get the standard LINQ queries like Select, Where, Orderby etc... What am I missing???


A very simple question on the LINQ Count function, but I can't figure it out....


Hi guys, I think this must be really simple but for some reason I can't get this to work.  I have an arraylist of stock ticker names and the same names can appear multiple times in the list.  I am trying to create a LINQ query to find which ticker names appear a certain number of times in the list. 

The arraylist is like: {Dell, Citi, Appl, Appl, Citi, Msft, Dell, Appl, Dell}

If I want to find which tickers appear 3 times in the list, which is named "stocklist", my current query is:


Dim newquery = From ticker In stocklist _

Where ticker.count = 3 _

Select ticker


But the query keeps giving me an error when I try to run it.  I'd greatly appreciate if someone could please let me know how to correct this problem.  Thanks in advance!

C#, LINQ: (List<>) Question???


Hi Everyone,

I have a strange problem:


There is an entity (Table) called "Filters" in my .edmx which has all my tables and stuff in it (to use it for LINQ queries)

I have created a class called "CustomFilters" which inherits "Filters". So now my cutom class has all the properties of the original "Filters" class (table) and 1 more additional property that i wanted which is a List of "CustomFilters":

List<CustomFilters> children = new List<CustomFilters>();

Now i get all my records into:

List<CustomFilters> theOriginalList = new List<CustomFilters>();

NOTE: first all records are tken into a List<Filters> and then these are added into List<CustomFilters> where List<CustomFilters> for children of that record is added, and then children of the child records, and so on......

so now, every record is an instance of CustomFilters which has a property named "children" which is a list again; and each child again has instanaces of "CustomFilters", and each instance again has children...and on and on and on.....

(basiacally its a data source for a treeview in my silverlight control)

every thing is good and working as expected.


Linq query to DataTable


Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.
     var row = from p in dc.ProductModels
                  select p;
    DataTable dt = row.CopyToDataTable();

Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.

     var row = from p in dc.ProductModels


Entity framework simple question




First I am newbie using EF - so sorry on this basic question


I have a Project Table that relate to Company Table


When I Map with EF I Do not have property of CompanyId in the Project Object

But I have related Company Object


For example

Project p = new Project();

p.CompanyId è does not exist!

When I try addingit myself I get this error:

If I need just the Company id, and I don't want get it like

p.Company.CompanyId - because than the application try connect again to the DB and I don't want this, because I need just the CompanyId.

What the best regular way to get it?


How to handle null while converting from my datatable to List<> using LINQ


I am converting my datatable to LISt using LINQ
how do I handle nulls coming from database

List<Port> portDetails = new List<Port>();
DataTable dt = ds.Tables[0];               
portDetails = (from q in dt.AsEnumerable()
select new Port
PortCode = q.Field<string>("Code"),
ExtCode = q.Field<string>("Nb"),
Name = q.Field<string>("Name"))

In the above query if Code is null I do not want property
portcode to be set to the value it should only set if it is
not null or not blank 
PortCode = q.Field<string>("Code"),

What should be syntax
I was trying somethign like this which doesnt work
Portcode = q.Field<bool>("Code") == null ? null : q.Field<bool>("Code")


A simple Data Modeling Question


I have a data modeling question that hopefully this fictious example will help explain.  My application is data driven and the classes reflect the tables to a large degree.   In this example my database has two tables:

  • VendorMaster with an int Primary Key of VendorID
  • VendorContact with an int Primary Key of ContactID

The VendorContact table also has a Foreign Key of VendorID in order to associate the contact with a specific Vendor.  In this example a Vendor can only have one contact.

My question is how to represent these two tables in terms of classes.  In my current design I have two classes:

  • VendorMaster
  • VendorContact

In order to represent the relationship between a VendorMaster and VendorContact, my VendorMaster class contains a property called VendorContact.

My questions are about the VendorContact class and how it represents the relationship between a VendorMaster and itself.

Option #1

The VendorContact class should contain an int property of VendorID

Option #2

The VendorContact class should contain a VendorMaster Property

I am not sure which option is the 'best' option to take. My concern is that if I go with option #2 that I would create a cyclical relationship between the VendorMaster and Vendo

GridView Question - Please Help Me...Should Be Simple...

Hello,I have what I think should be a simple GridView question but I can't find the answer.When I want to update a row in Gridview I click on the "Edit" link.  It takes me into the row of the GridView where I can edit the values.Here's how it looks:   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Edit 002 IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google When I click on "Edit" it looks like:   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Update Cancel IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google As you can see, I now have the ability to update the CustomerID.  I don't the user to be able to update the CustomerID, only the CompanyName via the DropDown.How can I change the GridView to ONLY allow me to update the CompanyName?ThanksJason   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Edit 002 IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google

Simple data binding question

Newbie binding question here: is it possible to bind a control in XAML to a StaticResource by passing in the key via a data structure? Basically something like this: <TextBlock Text="{Binding ImageKey}" /> <Image Source="{StaticResource ResourceKey={Binding ImageKey}}" /> <-- doesn't work   The TextBlock binding on the first line works correctly, it extracts the key of the StaticResource from my data structure and displays it correctly. What I'm trying to do is get the Image control to bind to the StaticResource with that name (which happens to be a BitmapImage).      

delete a row in datatable using linq to dataset

hihow can i delete a row in datatable using linq to dataset?I have a dataset in my project, need to delete some rows filtered by IDhow can i do?

Noob Question - Using Linq in View

I just inherited an MVC2 application. So far my only experience with MVC is reading the Nerd Dinner sample chapter and downloading the nerd dinner app. I do plan to dive much deeper but i need a quick answer because i have to hit the ground running. So basically in the main Index view the view model is being passed as an IQueryable. Then he is doing some queries on the view model to loop through the data. See example below:<% if (Model.Where(w => w.State == workflowStep.Key).Count() > 0) { %>To me, even though minor, this is business logic and shouldn't be in the view. Shouldn't any type of logic like this be sorted out before you get to the view? Or is this common practice in MVC?Basically i want to know if I should spend time refactoring this thing or just go with the flow.  Thanks.

Simple Question

hi i m using Resource file for localization everything cool I pick the date value and i format it then i set the HtmlTableCell InnerText value the date value shows in Thai format i don't want to show the date in thai language format how can i prevent this 

Simple Viewstate question

Consider a page with asp textbox and a button. textbox's "EnableViewstate" property is set as "False". In page directive also i set the Page's "EnableViewstate" property as "False". If i type some text (i.e., like "This is sample text") on the text box and click the command button. After the postback also that text box contains the same text ("This is sample text") which i have typed. I have set the view state in page for false. Then how the state is maintained?  whats the reason behind that? Thank you.

Simple Question

 Hi Guys,    I had a webservice method, Whenever it throws an Exception Object, I justwant to catch that Exception Object from the AJAX function. Is it possible? If so, please give sample code snippet ASAP.  Thanks in advance.

Linq to SQL - DeferredLoadingEnabled/DataLoadOptions Question

I am reading a book that suggests that when you need data from a child table that you should both: Set DeferredLoadingEnabled to false and Set the DataLoadOptions This seems a bit redundant to me.  If DeferredLoadingEnabled is false, why would you need to set the DataLoadOptions?  Doesn't turning off deferred loading mean that the child tables will automatically get loaded when the query is executed? Thanks

LINQ left outer join question

I can do this in other ways, but am looking for the "LINQ" way of doing this: Table1: People (PersonId,SchoolId)Table2: AssignedPeople (PersonId,SchoolId,RoomId) I want to select the people in Table1 within a particular SchoolId that are not in the assignedPeople table (in a particular Room).  The SQL is: select p.* from people p left outer join assignedpeople ap on p.PersonId=ap.Person and p.SchoolId=ap.SchoolIdand ap.RoomId=@roomId where p.SchoolId=@SchoolId and ap.PersonId is null I tried this LINQ (VB,NET):dim SchoolID as guid=...dim RoomID as guid=... (from p in dc.people where p.SchoolId=SchoolIdgroup join ap in dc.AssignedPeopleon p.PersonId equals ap.PersonId and p.SchoolId equals ap.SchoolId into groupfrom g in group.DefaultIfEmptywhere g.RoomID = nothing) but I can't get the ap.RoomId=@roomId part into the right place, should be something like:group join (from ap in dc.AssignedPeople where ap.RoomId=RoomId) Any help would be appreciated,Reuven

Another Simple Question - Adding a Picture to My Site

Hi, I'm trying to add a profile picture to my profile on SharePoint 2010 but under Edit my profile there isn't a option. I believe it should normally be under Basic Information. Is there a way to add this option?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend