how to build a DataView ?

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

I have a program manipulating DataTable and doing search in it
and returning a subset of them ...
moreover I don't use row filter but do the search 'manually'
is there a way I could create my DataView manually from this resul set ?
 
if the result set is already in a DataTable object then all you need to do
is
DataView dv = new DataView("dbTable");
Now you can access any of the available methods
dv.Sort("column to sort ASC")
etc ...

if the result set is a DataRow
DataRow dtRow = dbTable.NewRow();
dtRow["field1"] = value
dbTable.Rows.Add(dtRow);

Once this is complete create the DataView
 
mmhh..
you mean create a new DataTable with my DataRows and use the DataView of
this DataTable ?
mmhh.. that's an idea !

but I have one concern with it.
when I will add my (founded) DataRow to this new DataTable, don't I remove
them from their original DataTable ?

I think so....
anyway my find set should be small, so I might afford copying the data ...
mmhh....
that's a good lead ..

.Net Compact Framework said:
if the result set is already in a DataTable object then all you need to do
is
DataView dv = new DataView("dbTable");
Now you can access any of the available methods
dv.Sort("column to sort ASC")
etc ...

if the result set is a DataRow
DataRow dtRow = dbTable.NewRow();
dtRow["field1"] = value
dbTable.Rows.Add(dtRow);

Once this is complete create the DataView
Lloyd Dupont said:
I have a program manipulating DataTable and doing search in it
and returning a subset of them ...
moreover I don't use row filter but do the search 'manually'
is there a way I could create my DataView manually from this resul set ?
 
DataTable has a .Select method that may get you what you want. When you say
that you aren't using a RowFilter, is that a necessary thing? Rowfilters
seem made to order for what you want to do. There are many ways to get what
you want, but it depends on knowng what is the ultimate goal. You can use a
DataSet.GetChanges and then set its filter for things like Added, Modified
etc if this is what you want.

You can create a DataView off of ANY datatable, so there's most likely no
need to create a seperate table.. you can use the filter on the primary
table. But if you need to, you can create a second table and then a view,
and then filter it from there.

Let me know what you want to do...I can be of more help.

Cheers,

bill
 
in fact I realize that I could have a dataview as my data are just selected
with a criteria like column X equals Y

anwyay I found that the building of DataView through RowFilter to be slow.
I need to build DataView on user clic, and found that, even in a small
DataTable, it took a noticeable time (or maybe it was for my editor control
to appear, I don't know) so I was thinking to do the search myself (I know
the column type, I don't have to parse a string)
 
"but I have one concern with it
when I will add my (founded) DataRow to this new DataTable, don't I remov
them from their original DataTable ?

Answering to this doubt...if you add the founded data row directly to the data table then it will throw an exception saying that the row is already a part of some other table.So what you have to do is that you have to manually assign the values for all the columns in each row to the newly created row.Hope that it help

Shij
MC
 
Back
Top