Updating data using DataView

N

Nikhil Patel

Hi all,
I am using DataSet to store Sql Server Data in my ASP.Net application and
use it in several .aspx forms by saving it in Cache. In one of the forms, I
need to filter one of the tables in DataSet and display the result in an
Editable grid. I do this by creating a DataView by filtering the table in
the DataSet. The problem is saving the data from DataView back to the table
in DataSet. Do I need to loop through each row and see what changes have
been made or there is an easier way?
Thanks.
 
W

W.G. Ryan eMVP

No. When you make a change to the DataView object they are automatically
reflected in the table that its based on. You can verify this by checking
DataSet.HasChanges before you try your update.
 
G

Guest

If you bind a DataView, you are actually binding to the underlying rows in
the DataTable. When you change a row, the row is changed, regardless of how
it is bound.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
N

Nikhil Patel

Hi,
Thank you all for your replies. If the rows in the DataTable get changed
automatically then I guess I have a different problem. I lose the reference
to the underlying DataTable and the DataSet in the aspx form.

Here is the code. Page_Load works fine and I am able to see the rows in grid
and edit them. But I don't know how to save the data back to the DataSet
when the user clicks on a Button.

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
string sFieldName = Request.QueryString["FieldName"];
DataSet dataSetLookup = (DataSet) Application["Lookup"];

DataView viewLookup =
dataSetLookup.Tables["ProposalLookup"].DefaultView;
viewLookup.RowFilter = "FieldName = '"+sFieldName+"'";
viewLookup.Sort = "FieldValue";

gridLookup.DataSource = viewLookup;
gridLookup.DataBind();
}
}
 
W

W.G. Ryan eMVP

If you're losing it it's probably because of the post back. If you were to
store it in Session state for instance, you could deserialize it after the
post back and it would still retain its state.
Nikhil Patel said:
Hi,
Thank you all for your replies. If the rows in the DataTable get changed
automatically then I guess I have a different problem. I lose the reference
to the underlying DataTable and the DataSet in the aspx form.

Here is the code. Page_Load works fine and I am able to see the rows in grid
and edit them. But I don't know how to save the data back to the DataSet
when the user clicks on a Button.

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
string sFieldName = Request.QueryString["FieldName"];
DataSet dataSetLookup = (DataSet) Application["Lookup"];

DataView viewLookup =
dataSetLookup.Tables["ProposalLookup"].DefaultView;
viewLookup.RowFilter = "FieldName = '"+sFieldName+"'";
viewLookup.Sort = "FieldValue";

gridLookup.DataSource = viewLookup;
gridLookup.DataBind();
}
}


in message news:[email protected]...
If you bind a DataView, you are actually binding to the underlying rows in
the DataTable. When you change a row, the row is changed, regardless of
how
it is bound.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

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

Top