I am having one gridview on my web application....
It all working fine but not getting the result i want...


I have also used Edit and Delete Link as shoun in image 1....
When i click Edit button, then it can be edited... but when i click update the data gets updated easly... and also actual database gets updated....


I want the gridview should only get updated and not actual database.....
please help....

Recommended Answers

All 4 Replies

Hi,

1. On page load, Fill a DataTable with records retrieved from Database.
2. Store the DataTable in Session. Also bind the DataTable to the GridView.
3. In the Edit/Update events, Get the DatatTable from Session, Update/Edit the appropriate record in the DataTable, Store it in Session again, Re-bind the DataTable to GridView.

You can finally update the DataTable with database. After saving, clear the session variable which is used for storing it.

It is not advisable to store a large DataTable in Session.

I am not getting ...
if you have any example please attach here....

I have done upto this whats next...
please help...

SqlConnection conn = new SqlConnection("Data Source=XXX-578AC20261\\SQLEXPRESS;Initial Catalog=TT;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("SELECT * FROM Cust", conn);
        cmd.CommandType = CommandType.Text;
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataTable dt = new DataTable();
        da.Fill(dt);
        
Session["MyDataTable"] = dt;
        
        // To retrieve it from session
        dt = (DataTable)Session["MyDataTable"];

Enjoy !

Please remember Adapter.Update reflects your dataset to database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.