Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 18, 2012 04:33 AM by Decker Dong - MSFT
Member
63 Points
49 Posts
Nov 17, 2012 03:27 AM|LINK
Hi
I'm having following query in linq , I want to pass datatype as variable in datatable. but getting error
please advice
var tn = typeof(string);
string lcfield = "sub";
var tt = from r in mytbl.AsEnumerable()
where r.Field<tn>(lcfield) == "abc"
select new{
aaa = r.Field<tn>(lcfield)
};
Contributor
4240 Points
922 Posts
Nov 17, 2012 08:52 AM|LINK
So what you don't use string instead of tn ?
string lcfield = "sub"; var tt = from r in mytbl.AsEnumerable() where r.Field<string>(lcfield) == "abc" select new { aaa = r.Field<string>(lcfield) };
All-Star
118619 Points
18779 Posts
Nov 18, 2012 12:47 AM|LINK
subhankarpandey subhankarpandey
Hello,
Field<T> needs a certain field type insted of Type itself. So you can do the 2nd man's idea, or just say——
var tt = from r in mytbl.AsEnumerable() where r["fieldname"].ToString()=="Value" select new{ aaa = r["fieldname"].ToString() };
Nov 18, 2012 04:02 AM|LINK
Hello
I was asking datatype in fly that means datatype will be change depending on parameter pass not always string.
so tn sometime datatype may string , Int32 or decimal depening on tha value change as paremterwise
Nov 18, 2012 04:33 AM|LINK
subhankarpandey I was asking datatype in fly that means datatype will be change depending on parameter pass not always string.
Hi again,
You can still use my way——because every object will always have the ToString() method.
subhankarpan...
Member
63 Points
49 Posts
Linq datatype in the fly
Nov 17, 2012 03:27 AM|LINK
Hi
I'm having following query in linq , I want to pass datatype as variable in datatable. but getting error
please advice
var tn = typeof(string);
string lcfield = "sub";
var tt = from r in mytbl.AsEnumerable()
where r.Field<tn>(lcfield) == "abc"
select new{
aaa = r.Field<tn>(lcfield)
};
Subhankar
_Manvel_
Contributor
4240 Points
922 Posts
Re: Linq datatype in the fly
Nov 17, 2012 08:52 AM|LINK
So what you don't use string instead of tn ?
string lcfield = "sub"; var tt = from r in mytbl.AsEnumerable() where r.Field<string>(lcfield) == "abc" select new { aaa = r.Field<string>(lcfield) };Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Linq datatype in the fly
Nov 18, 2012 12:47 AM|LINK
Hello,
Field<T> needs a certain field type insted of Type itself. So you can do the 2nd man's idea, or just say——
var tt = from r in mytbl.AsEnumerable() where r["fieldname"].ToString()=="Value" select new{ aaa = r["fieldname"].ToString() };subhankarpan...
Member
63 Points
49 Posts
Re: Linq datatype in the fly
Nov 18, 2012 04:02 AM|LINK
Hello
I was asking datatype in fly that means datatype will be change depending on parameter pass not always string.
so tn sometime datatype may string , Int32 or decimal depening on tha value change as paremterwise
Subhankar
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Linq datatype in the fly
Nov 18, 2012 04:33 AM|LINK
Hi again,
You can still use my way——because every object will always have the ToString() method.