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?
 
Bob LearnedConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Bob LearnedCommented:
Are you looking to remove the results from the external database, or from the in-memory DataSet / DataTable instance?

Bob
0
 
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
 
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
All Courses

From novice to tech pro — start learning today.