-1

Sorry in advance that I don't know right terms to explain here.. but I will try

I am using LINQPad7 (C# statement(s)) my tables are from SQL database.

What I have is:

Table1

dateTime(DateTime) / ID(Int32) / Name(String)
2022-01-01         / 11111     / Jim
2022-01-02         / 22222     / Jack
2022-01-03         / 33333     / John

Table2

dateTime(DateTime) / ID(Int32) / Name(String)
2022-01-04         / 44444     / Bill
2022-01-05         / 55555     / Jane
2022-01-06         / 66666     / James

What I want is:

Table3

dateTime(DateTime) / ID(Int32) / Name(String)
2022-01-01         / 11111     / Jim
2022-01-02         / 22222     / Jack
2022-01-03         / 33333     / John
2022-01-04         / 44444     / Bill
2022-01-05         / 55555     / Jane
2022-01-06         / 66666     / James

also I would like to filter data so that I can get list of data that is after 2022-01-01.

what i have tried:

var t1 = table1.AsEnumerable().Where(b => b.dateTime > new DateTime(2022,01,01,00,00,00));
var t2 = table2.AsEnumerable().Where(b => b.dateTime > new DateTime(2022,01,01,00,00,00));

var mergedTable = t1.Concat(t2).Dump();

I think I am not even close... Is there anybody can make this happen using c#?

Thank you so much!!

  • You provided us some code that attempts to accomplish the problem. What exactly isn't working with your code? – mason May 18 '22 at 20:09
  • C# is a language of types, not pictures. What are your data types? PS It is a really bad idea to call `new` for a constant value inside LINQ. PPS you create `t1` and `t2` and never use them in your sample code - why? – NetMage May 18 '22 at 20:25
  • It happens that a [DataTable class](https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable?view=net-6.0) has a Merge method, a Copy method and even a Clone method. I would like to give an advice. Always look at the documentation of the classes that you want to use. Often the answer is already there. – Steve May 18 '22 at 20:33
  • Thank you for helping, I can't execute the code, it says "CS1929" 'IEnumerable' does not contain a definition for 'Concat' and best extension method overload ... requires a receiver of type 'parellelQuery' – beginnerProgramer12 May 18 '22 at 20:34
  • My table is from SQL database. – beginnerProgramer12 May 18 '22 at 20:42
  • NetMage - thank you for pointing out, I edited code table1 and table2 to t 1 and t2 – beginnerProgramer12 May 18 '22 at 20:47

0 Answers0