Creating an in memory table

H

HinduNationalist

I have the following Test.CSV file:
Col1,Col2,Col3
1,4,7
2,5,8
3,6,9

I have created a table:
DataColumn dc1 = new DataColumn("B1");
DataColumn dc2 = new DataColumn("B2);
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);

I want to select Col1, Col2 into dt.

How should I do it?
I can do the following:
using (OleDbCommand cmd =
new OleDbCommand("SELECT * FROM Test.csv" , conn))
{
da = new OleDbDataAdapter(cmd);
da.Fill(ds);
}

But I want to just have selected values into dt.
 
N

Nicholas Paldino [.NET/C# MVP]

If you only want selected values, then you will have to adjust the text
in your OleDbCommand to filter out the values you don't want to see.
 
H

HinduNationalist

If you only want selected values, then you will have to adjust the text
in your OleDbCommand to filter out the values you don't want to see.


Thank you for the reply.
But I am not able to understand ur suggestion.
Do you mean using (OleDbCommand cmd = new OleDbCommand("SELECT Col1,
Col2 into dt FROM Test.csv" , conn))

or something else?

-Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Yes, that's pretty much it. You will have to put a filter on it if you
want to filter out rows (a where clause) in the results.
 
H

HinduNationalist

Yes, that's pretty much it. You will have to put a filter on it if you
want to filter out rows (a where clause) in the results.
Thanks for reply.
I had already tried it. In OleDb it doesn't work.
 
N

Nicholas Paldino [.NET/C# MVP]

If it doesn't work, then you can load the entire contents into a
DataTable, and then create a DataView and place a filter on the items in the
DataTable through the view.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

AllowDBNull property 1
Get Data 3
Update Error in VS2005 with MS Access 1
Bug with DataColumn.AutoIncrementSeed 1
Store image (jpg) in datatable 5
delete in c# .net 1
Da.fill(ds); --error 7
excel read file 1

Top