473,396 Members | 1,864 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,396 software developers and data experts.

Record Added to Bound Datagrid on Refresh

I have a datagrid on a form that's bound to a datareader. When I click
on my browser's refresh button, it adds a duplicate record to the bottom
of the datagrid. This record appears in the underlying sql table. Why
would it do this? How do you stop it. I just want the datagrid to
display existing records, not modify the database.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim booTest As Boolean = False
If Not Me.IsPostBack Then
intAp = Me.Context.Items.Item("id")
Me.ViewState.Add("id", intAp)
Dim myConnection As SqlConnection = New SqlConnection
(ConfigurationSettings.AppSettings("MyDSN"))
Dim myCommand As SqlCommand = New SqlCommand("spOR_Guests",
myConnection)
myCommand.CommandType = CommandType.StoredProcedure

' @ApID bigint,
myCommand.Parameters.Add("@ApID", SqlDbType.BigInt)
myCommand.Parameters("@ApID").Direction =
ParameterDirection.Input
myCommand.Parameters("@ApID").Value = intAp
Dim dr As SqlDataReader
Try
' get balance
myConnection.Open()
dr = myCommand.ExecuteReader()
' get fee per day
If dr.Read Then
lblFee.Text = Format(dr("Fee"), "currency")
End If
dr.NextResult()
' get balance
If dr.Read Then
lblBalance.Text = Format(dr("Total"), "currency")
End If
dr.NextResult()
DataGrid1.DataSource = dr
DataGrid1.DataBind()
Catch exc As SqlException
Response.Write("SQL Error Occured: " & exc.ToString)

Catch exc As Exception
Response.Write("Error Occured: " & exc.ToString)

Finally
If Not dr Is Nothing Then
dr.Close()
End If
myConnection.Close()
End Try
Else
intAp = Me.ViewState.Item("id")
End If

End Sub
Nov 18 '05 #1
1 1188
The refresh button always repeat the last post to the server. You can't
change it. You can implement a sort of protection against repeating the same
operation in your code.

Eliyahu

"Jim Bayers" <sp**@spamity.spam> wrote in message
news:Xn*****************************@207.46.248.16 ...
I have a datagrid on a form that's bound to a datareader. When I click
on my browser's refresh button, it adds a duplicate record to the bottom
of the datagrid. This record appears in the underlying sql table. Why
would it do this? How do you stop it. I just want the datagrid to
display existing records, not modify the database.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim booTest As Boolean = False
If Not Me.IsPostBack Then
intAp = Me.Context.Items.Item("id")
Me.ViewState.Add("id", intAp)
Dim myConnection As SqlConnection = New SqlConnection
(ConfigurationSettings.AppSettings("MyDSN"))
Dim myCommand As SqlCommand = New SqlCommand("spOR_Guests",
myConnection)
myCommand.CommandType = CommandType.StoredProcedure

' @ApID bigint,
myCommand.Parameters.Add("@ApID", SqlDbType.BigInt)
myCommand.Parameters("@ApID").Direction =
ParameterDirection.Input
myCommand.Parameters("@ApID").Value = intAp
Dim dr As SqlDataReader
Try
' get balance
myConnection.Open()
dr = myCommand.ExecuteReader()
' get fee per day
If dr.Read Then
lblFee.Text = Format(dr("Fee"), "currency")
End If
dr.NextResult()
' get balance
If dr.Read Then
lblBalance.Text = Format(dr("Total"), "currency")
End If
dr.NextResult()
DataGrid1.DataSource = dr
DataGrid1.DataBind()
Catch exc As SqlException
Response.Write("SQL Error Occured: " & exc.ToString)

Catch exc As Exception
Response.Write("Error Occured: " & exc.ToString)

Finally
If Not dr Is Nothing Then
dr.Close()
End If
myConnection.Close()
End Try
Else
intAp = Me.ViewState.Item("id")
End If

End Sub

Nov 18 '05 #2

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

Similar topics

5
by: Mary Litten | last post by:
Hi - (This is my very first post) I have gotten to this point of registering to post because I have been spinning my wheels so long, I believe I am all caught up in the weeds. (and mud) I have...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
0
by: CSerpent | last post by:
AFTER A "REFRESH", HOW DO I RETURN THE USER TO THE RECORD HE WAS PREVIOUSLY WORKING WITH? I have a DataTable, and a bound DataGrid. The DataTable contains a column which is Unique, but the...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.