Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
DataTable dttable = new DataTable();
dttable.Columns.Add("billno", typeof(String));
dttable.Columns.Add("date", typeof(DateTime));
dttable.Columns.Add("time", typeof(String));
dttable.Columns.Add("covers", typeof(Decimal));
dttable.Columns.Add("trcode", typeof(String));
dttable.Columns.Add("scode", typeof(String));
dttable.Columns.Add("gname", typeof(String));
dttable.Columns.Add("total", typeof(Decimal));
dttable.Columns.Add("login", typeof(String));
dttable.Columns.Add("resno", typeof(String));
dttable.Columns.Add("custcode", typeof(String));
dttable.Columns.Add("resnum", typeof(Int32));
dttable.Columns.Add("sname", typeof(String));
dttable.Columns.Add("name", typeof(String));
dttable.Columns.Add("qty", typeof(Decimal));
dttable.Columns.Add("rate", typeof(Decimal));

var rows = from mobjbmast in Context.bmasts.AsEnumerable()
           join mobjbtran in Context.btrans
           on mobjbmast.billno equals mobjbtran.billno
           join mobjwaiter in Context.waiters
           on mobjbmast.scode equals mobjwaiter.code
           where mobjbmast.billno == mbillno
           select dttable.LoadDataRow(new object[]
           {
                 mobjbmast.billno,
                 mobjbmast.date,
                 mobjbmast.time,
                 mobjbmast.covers,
                 mobjbmast.trcode,
                 mobjbmast.scode,
                 mobjbmast.gname,
                 mobjbmast.total,
                 mobjbmast.login,
                 mobjbmast.resno,
                 mobjbmast.custcode,
                 mobjbmast.resnum,
                 mobjwaiter.name,
                 mobjbtran.name,
                 mobjbtran.qty,
                 mobjbtran.rate
           }, false);


The above code returns no rows in the datatable and on debugging the 'rows' variable show the error :

Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057

Please suggest. Thanks in advance.

What I have tried:

var rows = from mobjbmast in Context.bmasts.AsEnumerable()
           join mobjbtran in Context.btrans.AsEnumerable()
           on mobjbmast.billno equals mobjbtran.billno
           join mobjwaiter in Context.waiters.AsEnumerable()
           on mobjbmast.scode equals mobjwaiter.code
           where mobjbmast.billno == mbillno
           select new { billno = mobjbmast.billno, date = mobjbmast.date, time = mobjbmast.time, trcode = mobjbmast.trcode };


Even this gives the same error. If I change the AsEnumerable() to ToList() then I get Enumeration yielded no results.
Posted
Updated 13-Apr-19 0:22am
v2
Comments
Maciej Los 9-Apr-19 12:13pm    
Have you tried to use AsEnumerable() method with other data sources: Context.btrans, Context.waiters?
Priya-Kiko 10-Apr-19 1:55am    
Thank you for the response. Yes I did try with other data sources too adding AsEnumerable(). Yet the issue persisted.

You may try

C#
IEnumerable<DataRow> _query = ...... Your expression

DataTable boundTable = _query.CopyToDataTable<DataRow>();
 
Share this answer
 
v2
Comments
Priya-Kiko 11-Apr-19 3:47am    
Thanks for the response. I tried doing this as you suggested :

IEnumerable<datarow> _query = from mobjbmast in Context.bmasts.AsEnumerable()
join mobjbtran in Context.btrans.AsEnumerable()
on mobjbmast.billno equals mobjbtran.billno
join mobjwaiter in Context.waiters.AsEnumerable()
on mobjbmast.scode equals mobjwaiter.code
where mobjbmast.billno == mbillno
select mobjbmast;
But it doesn't compile. How to construct the query please help.
This code works for me. Got this solution from one of the websites. Posting this as answer so it can help some body else. The below code is for querying data from joined tables on some condition and loading a Datatable (with known columns) from the resultant object array.

DataTable dttable = new DataTable();

dttable.Columns.Add("billno", typeof(String));
dttable.Columns.Add("date", typeof(DateTime));
dttable.Columns.Add("time", typeof(String));
dttable.Columns.Add("covers", typeof(Decimal));
dttable.Columns.Add("trcode", typeof(String));
dttable.Columns.Add("scode", typeof(String));
dttable.Columns.Add("gname", typeof(String));
dttable.Columns.Add("total", typeof(Decimal));
dttable.Columns.Add("login", typeof(String));
dttable.Columns.Add("resno", typeof(String));
dttable.Columns.Add("custcode", typeof(String));
dttable.Columns.Add("resnum", typeof(Int32));
dttable.Columns.Add("sname", typeof(String));
dttable.Columns.Add("name", typeof(String));
dttable.Columns.Add("qty", typeof(Decimal));
dttable.Columns.Add("rate", typeof(Decimal));

var rows = from mobjbmast in Context.bmasts.AsEnumerable()
           join mobjbtran in Context.btrans
           on mobjbmast.billno equals mobjbtran.billno
           join mobjwaiter in Context.waiters
           on mobjbmast.scode equals mobjwaiter.code
           where mobjbmast.billno == mbillno
           let billarray = new object[]
           {
                mobjbmast.billno,
                mobjbmast.date,
                mobjbmast.time,
                mobjbmast.covers,
                mobjbmast.trcode,
                mobjbmast.scode,
                mobjbmast.gname,
                mobjbmast.total,
                mobjbmast.login,
                mobjbmast.resno,
                mobjbmast.custcode,
                mobjbmast.resnum,
                mobjwaiter.name,
                mobjbtran.name,
                mobjbtran.qty,
                mobjbtran.rate
            }
            select billarray;
            foreach (var array in rows)
            {
                dttable.Rows.Add(array);
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900