Select from a DataTable
-
I have a DataSet which has Two tables: TableAll, TableQueried TabelAll has all data available. What I want is to use a command to select only those rows in TableAll and copy them to TabelQueried which are LIKE some pattern. I knew how to do this when I had a database and used connections; but now there is no database. How should I do anything like this command: "SElECT * FROM TABELALL WHERE Data LIKE [pattern]"
-
I have a DataSet which has Two tables: TableAll, TableQueried TabelAll has all data available. What I want is to use a command to select only those rows in TableAll and copy them to TabelQueried which are LIKE some pattern. I knew how to do this when I had a database and used connections; but now there is no database. How should I do anything like this command: "SElECT * FROM TABELALL WHERE Data LIKE [pattern]"
I assume you are talking about an ADO.NET way? If so look at DataTable.Select(CriteriaString). I think the select method has an override for an order by clause. Criteriastring is a string in the format of: (column name) expressions such as = or like or in; google datatable.select to get list of expressions. And then the criteria, very similar to a where condition in a sql statement. IE for examaple
DataRow[] rows = myDataTable.Select("Column1 = 25","column1 asc")
This will return an array of DataRows which you can then work with. Hope this helps! Aaron
_____________________________________________________________________ Our developers never release code. Rather, it tends to escape, pillaging the countryside all around. The Enlightenment Project (paraphrased comment) Visit Me at GISDevCafe
-
I assume you are talking about an ADO.NET way? If so look at DataTable.Select(CriteriaString). I think the select method has an override for an order by clause. Criteriastring is a string in the format of: (column name) expressions such as = or like or in; google datatable.select to get list of expressions. And then the criteria, very similar to a where condition in a sql statement. IE for examaple
DataRow[] rows = myDataTable.Select("Column1 = 25","column1 asc")
This will return an array of DataRows which you can then work with. Hope this helps! Aaron
_____________________________________________________________________ Our developers never release code. Rather, it tends to escape, pillaging the countryside all around. The Enlightenment Project (paraphrased comment) Visit Me at GISDevCafe
THANK YOU!! ;) You really helped me out! :rose: I was JUST looking for this.
-
THANK YOU!! ;) You really helped me out! :rose: I was JUST looking for this.
The only caveat you need to remember is that the datatable select consumes quite a bit of memory as it has to go through every record in the table. Be sure to set a primary key column and index if possible. Aaron
_____________________________________________________________________ Our developers never release code. Rather, it tends to escape, pillaging the countryside all around. The Enlightenment Project (paraphrased comment) Visit Me at GISDevCafe