Extract a filtered view from a dataview

  • Thread starter Thread starter Romain TAILLANDIER
  • Start date Start date
R

Romain TAILLANDIER

Hi group

I have a DataGrid which showing a view of a single table from a database.
that view is obtained from a DataView, by filtering rows, and showing the
rigth columns.

I have to save that particuliar view in a CSV file or so, and i am only be
able to extrat the entiere table.

Can you help ?

thanks
ROM
 
I'm not exactly sure how you want to do this, but one alternative might be
to use the DataTable.Select method.
IE. authorsSet.authors.Select("state = 'CA'") would return a DataRow array
with all authors in California from a typed dataset on the pubs database.
In case of a DataView you could use theDataView.Table.Select(expression) to
retrieve the filtered data.
These could in turn be added to an empty datatable when you reload the data
from the csv file, or you could use the csv file as a source for the table.
You'd have to write the text file manually by iterating through the array of
rows though..

HTH,
Lars-Erik
 
thanks for your respond lars-eric.

It seems my question was'nt asked correctly, but your respond was usefull...
here is the code i have write to do what i was need :

string res = "";
StreamWriter myWriter = new StreamWriter(sfd.FileName);
foreach(DataRowView row in MyDataView)
{
res = "";
for(int i = 0; i<row.Row.ItemArray.Length; ++i)
{
if(MyDataView.Table.Columns.ColumnMapping == MappingType.Element)
res += row.Row.ItemArray.ToString() + ";";
}
myWriter.Write( res.TrimEnd(';') + "\r\n");
}
myWriter.Close();


ROM
 
So you got it working the way you wanted allready? :)

L-E

Romain TAILLANDIER said:
thanks for your respond lars-eric.

It seems my question was'nt asked correctly, but your respond was usefull...
here is the code i have write to do what i was need :

string res = "";
StreamWriter myWriter = new StreamWriter(sfd.FileName);
foreach(DataRowView row in MyDataView)
{
res = "";
for(int i = 0; i<row.Row.ItemArray.Length; ++i)
{
if(MyDataView.Table.Columns.ColumnMapping == MappingType.Element)
res += row.Row.ItemArray.ToString() + ";";
}
myWriter.Write( res.TrimEnd(';') + "\r\n");
}
myWriter.Close();


ROM


Lars-Erik Aabech said:
I'm not exactly sure how you want to do this, but one alternative might be
to use the DataTable.Select method.
IE. authorsSet.authors.Select("state = 'CA'") would return a DataRow array
with all authors in California from a typed dataset on the pubs database.
In case of a DataView you could use theDataView.Table.Select(expression) to
retrieve the filtered data.
These could in turn be added to an empty datatable when you reload the data
from the csv file, or you could use the csv file as a source for the table.
You'd have to write the text file manually by iterating through the
array
of
rows though..

HTH,
Lars-Erik
only
 
Yes !

Do you see some possibly problem i could have with that code ? (note that it
is in a try catch block)

thanks
ROM


Lars-Erik Aabech said:
So you got it working the way you wanted allready? :)

L-E

Romain TAILLANDIER said:
thanks for your respond lars-eric.

It seems my question was'nt asked correctly, but your respond was usefull...
here is the code i have write to do what i was need :

string res = "";
StreamWriter myWriter = new StreamWriter(sfd.FileName);
foreach(DataRowView row in MyDataView)
{
res = "";
for(int i = 0; i<row.Row.ItemArray.Length; ++i)
{
if(MyDataView.Table.Columns.ColumnMapping == MappingType.Element)
res += row.Row.ItemArray.ToString() + ";";
}
myWriter.Write( res.TrimEnd(';') + "\r\n");
}
myWriter.Close();


ROM


Lars-Erik Aabech said:
I'm not exactly sure how you want to do this, but one alternative
might
be theDataView.Table.Select(expression)
to array showing
the only
 
Sorry, I can't see any problems in your code.

Lars-Erik

Romain TAILLANDIER said:
Yes !

Do you see some possibly problem i could have with that code ? (note that it
is in a try catch block)

thanks
ROM


Lars-Erik Aabech said:
So you got it working the way you wanted allready? :)

L-E

thanks for your respond lars-eric.

It seems my question was'nt asked correctly, but your respond was usefull...
here is the code i have write to do what i was need :

string res = "";
StreamWriter myWriter = new StreamWriter(sfd.FileName);
foreach(DataRowView row in MyDataView)
{
res = "";
for(int i = 0; i<row.Row.ItemArray.Length; ++i)
{
if(MyDataView.Table.Columns.ColumnMapping == MappingType.Element)
res += row.Row.ItemArray.ToString() + ";";
}
myWriter.Write( res.TrimEnd(';') + "\r\n");
}
myWriter.Close();


ROM


"Lars-Erik Aabech" <[email protected]> a écrit dans le
message de news: (e-mail address removed)...
I'm not exactly sure how you want to do this, but one alternative
might
be
to use the DataTable.Select method.
IE. authorsSet.authors.Select("state = 'CA'") would return a DataRow array
with all authors in California from a typed dataset on the pubs database.
In case of a DataView you could use theDataView.Table.Select(expression)
to
retrieve the filtered data.
These could in turn be added to an empty datatable when you reload the
data
from the csv file, or you could use the csv file as a source for the
table.
You'd have to write the text file manually by iterating through the array
of
rows though..

HTH,
Lars-Erik

Hi group

I have a DataGrid which showing a view of a single table from a
database.
that view is obtained from a DataView, by filtering rows, and showing
the
rigth columns.

I have to save that particuliar view in a CSV file or so, and i am only
be
able to extrat the entiere table.

Can you help ?

thanks
ROM

 
Back
Top