Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4617718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:09:51+00:00 2026-05-22T02:09:51+00:00

First apologies if I don’t explain this properly, I’ve been at this for hours,

  • 0

First apologies if I don’t explain this properly, I’ve been at this for hours, and it’s now morning.

I’ve tried so many methods, got so many errors that I can’t remember the original version, nor can I solve the problem, here’s my code, it’s terrible as I should be using a join query my SP’s are bugged on this server.

SqlConnection conn = new SqlConnection(connstring);
DataSet ds = new DataSet();
SqlDataAdapter ad;
SqlCommand cmd = new SqlCommand();
ad = new SqlDataAdapter("SELECT * FROM booking WHERE bookstartdate BETWEEN '" + ReturnDbDate(datefrom).ToString() + "' AND '" + ReturnDbDate(dateto).ToString() + "'", conn);
ad.Fill(ds, "CustomerIds");

ad = new SqlDataAdapter("SELECT customerid, firstname, lastname, telephone, email FROM customer", conn);
ad.Fill(ds, "Customers");

DataTable dt = new DataTable();
dt.Columns.Add("Customerid", typeof(String));
dt.Columns.Add("Firstname", typeof(String));
dt.Columns.Add("Lastname", typeof(String));
dt.Columns.Add("Telephone", typeof(String));
dt.Columns.Add("Email", typeof(String));

int lol = ds.Tables["CustomerIds"].Rows.Count;

foreach (DataRow row in ds.Tables["CustomerIds"].Rows)
{
    IEnumerable<DataRow> r = from dr in ds.Tables["Customers"].AsEnumerable()
                             where dr.Field<Guid>("customerid").ToString() == row[2].ToString()
                             select dr;
    dt.Rows.Add(r);
}

return dt;

When I try loop through the dataset using the following:

foreach (DataRow rows in dt.Rows)
{
    sb.Append("<tr><td>" + rows["Customerid"].ToString() + "</td><td>" + rows[1] + "</td><td>" + rows[2] +"</td><td>" + rows[3] + "</td></tr>");
}

I get:

System.Data.EnumerableRowCollection`1[System.Data.DataRow]

Anyone any ideas? Completely brain dead atm so it might be something simple.

Thanks

Edit:

DataRow r = from dr in ds.Tables["Customers"]
            where dr.Field<Guid>("customerid").ToString() == row[2].ToString()
            select dr;    
dt.ImportRow(r);

Error: Could not find an implementation of the query pattern for source type ‘System.Data.DataTable’. ‘Where’ not found.

I’m assuming my LINQ syntax is not incorrect, although I think there’s a IEnumberable<T>.Where() method? I remember it, just can’t remember how to access it.

Edit2:

I fail, managed to re-create the problem again, sigh

 IEnumerable<DataRow> r = from dr in ds.Tables["Customers"].Select().Where(x => x.Field<Guid>("customerid").ToString() == row[2].ToString())
                            select dr;



                dt.ImportRow(r);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:09:52+00:00Added an answer on May 22, 2026 at 2:09 am

    dt.Rows.Add() takes in a DataRow but your providing IEnumerable<DataRow>
    Also note that rows can only be added to a DataTable that has been created with dt.NewRow() try using dt.ImportRow() instead

    EDIT:

    Skip the temp DataTable and join the two datatables in the dataset instead.
    Or even better, skip using linq and join the tables in the database query instead.

    return 
      from dr in ds.Tables["Customers"].AsEnumerable()
      join dr2 in ds.Tables["CustomerIds"].AsEnumerable()
        on dr.Field<Guid>("customerid") equals dr2.Field<Guid>(2)
      select dr;
    

    Plain SQL

    public DataTable GetCustomers(DataTime datefrom, DataTime dateto)
    {
        var sql = @"
            SELECT customer.customerid, firstname, lastname, telephone, email
            FROM customer
            JOIN booking
                ON customer.customerid = booking.customerid
            WHERE bookstartdate BETWEEN '" + ReturnDbDate(datefrom).ToString() + "' AND '" + ReturnDbDate(dateto).ToString() + "'";
    
        using (SqlConnection conn = new SqlConnection(connstring))
        using (SqlDataAdapter ad = new SqlDataAdapter(sql, conn))
        {
                DataSet ds = new DataSet();
                ad.Fill(ds);
                return ds.tables[0];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My apologies if this question is too general, as this is my first time
Apologies if this is a very simple question; I don't use XSLT very much
N.B This question has been significantly edited before the first answer was given. Hi,
I am new to python, apologies if this has been asked already. Using python
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS
First and foremost, I apologize for any vagueness in this question. At this point,
First off, there's a bit of background to this issue available on my blog:
(First question related to iPhone development, so apologies for sounding off-track.) I'm creating a
I'm a student of web development (and college), so my apologies if this comes
I have a very novice question, so apologies if the answer to this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.