tags:

views:

93

answers:

2

I am getting error msg on the word Records - Type or namespace could not be found. Please help debugging it, what is missing?

 if (ProjDDL1.SelectedItem.Value != "--") results = CustomSearch<Records>(results, s => s.Business == ProjDDL1.SelectedItem.Value);

Method CustomSearch:

 private DataTable CustomSearch<TKEY>(DataTable dt, Func<Records, bool> selector)
{
    DataTable results = (dt.AsEnumerable().Where(selector).CopyToDataTable());
    return results;
}
A: 

Visual Studio will normally underline the item that's erroring when compiled. If you click on it and press Shift-Alt-F10, it will allow you to automatically add the namespace to the code. If you don't get a suggestion, this means that you haven't referenced the DLL that it needs.

Pete OHanlon
I did what you said but and Shift alt F10 added a methos CustomSearch, but stil I am getting red line under word records in Records.
menon
You need to do this under Records.
Pete OHanlon
yes, I clicked on Records and pressed aly shift F10. and it fif not add any namespace.
menon
If it doesn't find any namespace, this normally means you haven't added the DLL that Records is in as a reference.
Pete OHanlon
this is what I have, anything missing?using System;using System.Data;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI.WebControls;using System.Linq.Expressions;using System.Web.UI;
menon
I assume that Records is something that belongs in one of your classes, so you need to add a reference into your project for the dll that contains this class.BTW - your CustomSearch method declares a generic which isn't used anywhere in the method. Should this actually read:private DataTable CustomSearch<TKEY>(DataTable dt, Func<TKEY, bool> selector)
Pete OHanlon
Getting error on >(DataTable dt, Func<TKEY, bool> selector)
menon
I get results from a dataset, which is then searched and returned to datatable, DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable() orderby d.Field<string>("Name") ascending where (d.Field<string>(columnName) != null) if (ProjDDL1.SelectedItem.Value != "--") results = CustomSearch<Records>(results, s => s.Business == ProjDDL1.SelectedItem.Value);
menon
I don't know anything about dll and I don't think I can add any.
menon
it is the using System.Linq.Dynamic; and I have addes Dynamic.cs in app_code but stil getting error on CustomSearch call in method
menon
A: 

Well, if it doesn't know what Records means, look at your references and using directives. Which namespace is the Records type in?

Why is your CustomSearch method generic anyway? It doesn't seem to use TKEY anywhere...

Jon Skeet
I am absolutely new to linq expression, please tell me what should teh correct syntax or code.
menon
Am I missing anything in namespaces, I think I have them:using System;using System.Data;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI.WebControls;using System.Linq.Expressions;using System.Web.UI;
menon
some more code DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable() orderby d.Field<string>("Name") ascending where (d.Field<string>(columnName) != null) if (ProjDDL1.SelectedItem.Value != "--") results = CustomSearch<Records>(results, s => s.Business == ProjDDL1.SelectedItem.Value);
menon
What is TKEY and what does it do?
menon
TKEY is the generic type parameter in the CustomSearch method you posted. You're the one who should know what it's for :)
Jon Skeet
You haven't shown any using directives other than System ones - what namespace is your "Records" type in?
Jon Skeet
I don't have any directives, don't know, copied it from a forum and modified it , absolutely new to linq query expression, please suggest what should be the correct code.
menon
You do have using directives - you just showed them. ("using System;" etc). You still haven't shown what type Records is or what namespace it's in though.
Jon Skeet
My guess is its in using System.Linq.Expressions;
menon
I have a dataset _Mydataset passed to the method and that dataset is queried by linq and retunrd to results datatable --- DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable() orderby d.Field<string>("Name") ascending where (d.Field<string>(columnName) != null) if (ProjDDL1.SelectedItem.Value != "--") results = CustomSearch<Records>(results, s => s.Business == ProjDDL1.SelectedItem.Value);
menon
So I can see records in from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable(), which is not giving any error.
menon
@menon: No, the `Records` type *isn't* in System.Linq.Expressions. It's meant to be *your business type*. Really, you need to start from scratch and learn LINQ properly - it'll be a lot faster than trying this cut-and-paste coding.
Jon Skeet
its in the using System.Linq.Dynamic; and I have addes Dynamic.cs in app_code but stil getting error on CustomSearch call in method.
menon
@menon: I really doubt that it's in System.Linq.Dynamic... or if it is, I don't think it should be. You may well just have sample code which isn't really meant to be cut and pasted into a real app. I'm afraid this isn't the best way of learning LINQ from scratch.
Jon Skeet