473,320 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

saving data back to dataset

Hi,
I bind a grid to a DataView object. I lose the reference to the underlying
DataTable and the DataSet in a postback.

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 database
when the user clicks on a Button. Thanks.

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();
}
}
Nov 18 '05 #1
1 1812
It's definitely not like saving a dataset in a windows app. You have to pull
the edited values off of your grid and update them one at a time. Use the
edititemTemplate of the grid to set up text boxes and whatever for the user
to modify the values. Then in the update command pull the values from those
textboxes and pass to your database through stored procredures.

//datagrid html
<EDITITEMTEMPLATE>
<ASP:TEXTBOX class="text" id="txtEditCatTitle" runat="server" text='<%#
DataBinder.Eval(Container.DataItem, "dc_title")%>' size="30">
</ASP:TEXTBOX>
</EDITITEMTEMPLATE>

//the update command
private void dgCats_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Admin data = new Admin();
int ID = Convert.ToInt32(e.Item.Cells[0].Text);
string Title = ((TextBox) e.Item.FindControl("txtEditCatTitle")).Text;
data.UpdateDocumentCategory(ID, Title);

//reset the form
dgCats.EditItemIndex = -1;
RefreshGrids();
}
"Nikhil Patel" wrote:
Hi,
I bind a grid to a DataView object. I lose the reference to the underlying
DataTable and the DataSet in a postback.

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 database
when the user clicks on a Button. Thanks.

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();
}
}

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Oldhandandy | last post by:
I have a datagrid linked to a SQL Stored Procedure, the data is extracted from 4 tables. Data is only updated not inserted and the update is to only 1 of the tables, the other three tables are...
5
by: adrin | last post by:
hi, i am writing a program that is supposed to create a database of my music and albums. i want it to consist of 3 'modules' input<->processing<->output. input should enable reading data from cd...
2
by: Dennis | last post by:
Hi, I am hoping I can get some help with a small problem I have run into using C#. U have an XML file that I load into a Dataset and then display this in a Datagrid. No problems doing this at all....
1
by: Steven Thomas | last post by:
Can some one help me find a code snipit for saving the contents of a data set to a comma seperated file? I have created a web service in asp.net that will read the data from a AS/400 DB2...
1
by: Bernard O'Flynn | last post by:
Hi I have a pivot table that gets it data from another worksheet in the workbook. I need to update the data worksheet from data in a database (I'm using MS Data Application Block) and get a...
1
by: Sanjeev Mahajan via .NET 247 | last post by:
Hi All, I have a main page from which I am calling a popup page. Thepopup page has an editable grid and some other fields. There isalso a Save button on the popup page. When the user clicks...
11
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a...
5
by: Lucvdv | last post by:
This would better be described by 'serialization' than 'interop', but I didn't find a newsgroup that seems closer on topic. The problem in a few words: I save data with DataSet.WriteXML, but I...
1
by: romcab | last post by:
Hi guys, I would like to ask your help about saving in ado.net. I was able to update it only on the display but when I check the database, it is not updated. I paste below my code and hopefully...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.