重复插入错误 [英] Duplicate inserts error
本文介绍了重复插入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我为什么下面的代码在一个实例而不是另一个实例中插入重复的行.我检查了网格属性,它们也完全相同:
受保护的 子 GridView1_SelectedIndexChanged(发送方 As 对象,e As EventArgs)处理 grdPANSSAssessmentSelect.SelectedIndexChanged
Dim AssessCode As 字符串 = CType (Session.Item(" ), 字符串)
会话(" )= grdPANSSAssessmentSelect.SelectedRow.Cells.Item( Dim GetAssDate As 字符串
GetAssDate = Format(日期.今天," )
' GetAssDate = Strings.Format(Date.Today,"dd/MM/yyyy")
Dim sql As 字符串 = " &会话(" )& " &会话(" )& _
" & GetAssDate& " & GetAssDate& " & GetAssDate& "
Dim myConnection As 新建 SqlConnection(ConfigurationManager. ConnectionStrings(" ).ConnectionString)
Dim myCommand As New SqlCommand(sql, myConnection)
Dim myReader As SqlDataReader
myConnection.Open()
' Dim阅读器为SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' myCommand.ExecuteNonQuery()
myReader = myCommand.ExecuteReader
如果 myReader.RecordsAffected> 0 然后
Response.Redirect(" )
其他
ClientScript.RegisterStartupScript(我. GetType ," 测试", < script language ='javascript '> alert(插入评估似乎有问题.请与管理员联系!);</script>")
结束 如果
myReader.Close()
myConnection.Close()
结束 子
解决方案
确实是一个非常困难的错误.
花了我30多分钟.
只需删除
句柄 grdPANSSAssessmentmentSelect.SelectedIndexChanged
或在aspx源文件中找到
onrowdatabound = "
并将其删除.
如果两者都存在,则该事件将被调用两次.
删除任何一个.
它应该可以正常工作
谢谢.希望它不会花费太多时间...:-)
Can someone please tell me why the code below inserts duplicate rows in the one instance and not the other. I checked the grid properties and they are also exactly the same:
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles grdPANSSAssessmentSelect.SelectedIndexChanged
Dim AssessCode As String = CType(Session.Item("AssessCode"), String)
Session("AssessCode") = grdPANSSAssessmentSelect.SelectedRow.Cells.Item(2).Text
Dim GetAssDate As String
GetAssDate = Format(Date.Today, "dd/MM/yyyy")
'GetAssDate = Strings.Format(Date.Today, "dd/MM/yyyy")
Dim sql As String = "AddAssessment " & Session("ClientID") & "," & Session("AssessCode") & _
",4,'" & GetAssDate & "', '" & GetAssDate & "','" & GetAssDate & "',0,0,0,0,0"
Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("CameoAssessmentRegisterConnectionString").ConnectionString)
Dim myCommand As New SqlCommand(sql, myConnection)
Dim myReader As SqlDataReader
myConnection.Open()
'Dim reader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
'myCommand.ExecuteNonQuery()
myReader = myCommand.ExecuteReader
If myReader.RecordsAffected > 0 Then
Response.Redirect("frmPANSS.aspx")
Else
ClientScript.RegisterStartupScript(Me.GetType, "test", "<script language='javascript'>alert('There seems to be a problem inserting the assessment. Contact Administrator!);</script>")
End If
myReader.Close()
myConnection.Close()
End Sub
解决方案
Hi
really a very difficult bug.
took me more than 30 mins.
just remove the
Handles grdPANSSAssessmentSelect.SelectedIndexChanged
or in the aspx source file findonrowdatabound="GridView1_RowDataBound"and remove it.
if both are present, then the event will be called twice.
remove any one.
It should work
Thank you. Hope it didn''t take too much out of your day...:-)
这篇关于重复插入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文