ADO.NET: Remove data after postback?

Hello,

I have an application that has an Page_Load Event, Click Event to retive data, and another Click Event that Updates data. Everything occurs on the same page. The Event to retrieve data binds the data to a dataset and the Update event modifies all data and after the Update the page goes back to the original users data until some else enters a new search. I would like to be able to clear the results after the Update Event.

Thanks in Advance!!
LVL 4
asp_net2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
1) ASP.NET 2.0?

2) Data-binding method:  SqlDataSource, AccessDataSource, ...?

3) Database type:  SQL Server, Access, Oracle, ...?

Bob
0
asp_net2Author Commented:
TheLearnedOne,

Sorry, I left out the important stuff. Damn newbies.

1. ASP.NET 2 and 3.5
2. Using ADO.NET with SQLDataAdapter and DataSet
3. SQL Server
0
Bob LearnedCommented:
Are you looking to remove the results from the external database, or from the in-memory DataSet / DataTable instance?

Bob
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

asp_net2Author Commented:
Just looking for a way to remove the data from the dataset after the Update Event fires. After the update is complete and the data is not on the form then I would like the user to enter another entry and pull the data in using the same dataset.
0
asp_net2Author Commented:
Here is the code that I use for retrieving the results to the form. I can also send you the code for my update if needed. Thanks again in advance.
CodeForRetrieve.txt
0
Bob LearnedCommented:
If you are looking to clear the in-memory DataSet, then you should be able to use the DataSet.Clear method.

Bob
0
asp_net2Author Commented:
Can you give me sample of what you mean? I'm still learning and not to sure where to put that at. Do you need to see my update code?
0
Bob LearnedCommented:
No, I wouldn't need to see your code.

This is a pretty simple method to use.  The difficult part is deciding where to put it.

Bob



0
Bob LearnedCommented:
Web page
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
		&nbsp;
		<asp:GridView ID="GridView1" runat="server" Height="160px" Style="z-index: 102; left: 14px;
			position: absolute; top: 15px" Width="560px">
		</asp:GridView>
    
    </div>
		<asp:Button ID="ClearButton" runat="server" Style="z-index: 101; left: 88px; position: absolute;
			top: 216px" Text="Clear" />
    </form>
</body>
</html>

Open in new window

0
Bob LearnedCommented:
Code-behind:
Imports System.Data
Imports System.Data.SqlClient
 
Partial Class _Default
	Inherits System.Web.UI.Page
 
	Private m_data As DataSet = Nothing
 
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		If Not Page.IsPostBack() Then
			' Get the employee data from database based on employee ID (query string 'empid').
			Me.GetEmployeeData()
		Else
			' Get the data persisted in memory.
			m_data = CType(Session("MyData"), DataSet)
		End If
 
		' Bind the DataSet to the GridView.
		Me.GridView1.DataSource = m_data
		Me.GridView1.DataBind()
	End Sub
 
	Private Sub GetEmployeeData()
 
		' Define the connection string and the SQL query
		Dim connectionString As String = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
		Dim commandText As String = "Select * From Employee Where EmployeeID = " & Request.QueryString("empid")
 
		Using adapter As New SqlDataAdapter(commandText, connectionString)
 
			' Get the data and persist it in memory.
			m_data = New DataSet()
			adapter.Fill(m_data)
 
			Session("MyData") = m_data
		End Using
	End Sub
 
	Protected Sub ClearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ClearButton.Click
		' Clear the DataSet, and re-bind the GridView to clear the results.
		m_data.Clear()
		Session("MyData") = m_data
 
		Me.GridView1.DataSource = m_data
		Me.GridView1.DataBind()
	End Sub
 
End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asp_net2Author Commented:
I'm sorry I do not understand how to tie that in to what I have now.
0
Bob LearnedCommented:
Well, first of all, does it make sense?  What you can do is to create a temporary web site, and put that code into the Default.aspx that gets created.  Then, you can get it running, and see what it does, in order to understand it.

Bob
0
asp_net2Author Commented:
TheLearnedOne,

No I really don't understand what you mean by declare a dataset as a session. Also, I would like to know if what I code is correct to do what i'm asking. I really don't understand what you did compared to what I have. Sorry.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.