Is there possible to write such a sql query by linc in C#?
I have two tables (kv2, kv2dns), I want to select destination feild from kv2dns which has some common condition with kv2 table
if (dt.dport=53) dt is datatable for kv2 table has
{
list hosts = Select destination_address from kv2dns where kv2.saddr=kv2dns.destination_ address and kv2.daddr=kv2dns.source and kv2dns.info like ' no such name' ;
}
Jignesh TrivediPosted Sep 9, 2013, 12:00 AM
hi,
If both kv2 and kv2dns are data table then
var kv2 = ds.Tables["kv2"].AsEnumerable();
var kv2dns = ds.Tables["kv2dns"].AsEnumerable();
var query =("source")("destination_address") ("info").Contains("name")
from a in kv2
join b in kv2dns on a.Field
equals b.Field
where b.Field
select new
{
DA = b.destination_address
};
hope this will help you.
diamond diamondPosted Sep 6, 2013, 11:26 AM
diamond diamondPosted Sep 6, 2013, 8:55 AM
kv2dns has some fields such as source, destination, info
src and destination values are the same.
dst and source values are the same.
but no tables have primary key
diamond diamondPosted Sep 6, 2013, 8:49 AM
I have 2 table kv2 and kv2dns, which kv2 has a data table is named dt but kv2dns has not.
I want if dt.dport field be 53, hen compare dt with kv2dns for knowing that is there any dt.src=kv2dns.dst and kv2dns. info has 'no such name', if ok the kv2dns.dst is put in a list
Jignesh TrivediPosted Sep 6, 2013, 8:17 AM
not sure why you are write such complicated query.
can please me details like
1) are you use datatable or dataset to retrieve the data?
2)provide relationship between table
here you are writting from clause just before where....
actually syntex of Linq is wrong.
without knowing relation i am not able to write query.
diamond diamondPosted Sep 6, 2013, 7:16 AM
When I wrote such as below, gives an error.
Jignesh TrivediPosted Sep 6, 2013, 3:51 AM
hi,
using "Contains" key word you can achieve functionality same as like key word in SQL.
example.
var host = from kv2 in kv2dns
where v2.saddr equals kv2dns.destination_address && kv2.daddr equals kv2dns.source && kv2dns.info.Contains("no such name")
select { destination_address }
hope this will help you.