J
Jim Bayers
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
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