Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Button click handle inserting 2 records instead of 1 record into SQLButton click handle inserting 2 records instead of 1 record into SQL
Previous
 
Next
New Post
9/5/2008 1:55 PM
 

 know this is probably something simple but my button click handle is inserting 2 records in my SQL table when it should be inserting 1 record. Can anyone determine what this could be.



here is the code:



Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

dreader.Close()

strSql = "select statusdesc,contact.statusid from Contact inner join contactstatus on contact.statusid = contactstatus.statusid where contact.contactid = '" & contid & "'"

conn = New SqlClient.SqlConnection(strconn)

sqlcmd2 = New SqlCommand(strSql, conn)

conn.Open()

dreader2 = sqlcmd2.ExecuteReader()

dreader2.Read()

Me.Label1.Text = dreader2.Item(1).ToString

'conn.Close()


strSql = "insert into ContactHistory(contactid,statusid,userid,note) values('" & Me.lblInquiry.Text & "','" & Me.Label1.Text & "','" & Session("userid") & "','" & Me.txtNote.Text & "')"

conn = New SqlClient.SqlConnection(strconn)

conn.Open()

Dim Com As New System.Data.SqlClient.SqlCommand(strSql, conn)

Com.CommandText = strSql

Com.ExecuteNonQuery()

conn.Close()


'SetFocus(Me.TextBox3)

End Sub

 

 
New Post
9/5/2008 2:34 PM
 

This is very interesting... have you tried stepping through with the debugger and strategically placing the breakpoints in a few places to see why the event is calling more than once?

An observation not related to the inserting is that this code is VERY prone to SQL injection attacks.  You would be much better served using stored procedures or, in the least, parameterizing your query.  So the select would have "...where contact.contactid = @someParam" and then add to the sqlmd2.Params a value matching that name and type.  Using parameterized queries still gives you the flexibility of a dynamic query but the safety of a stored procedure (somebody putting in a 'truncate table contacthistory;' as their txtNote won't actually truncate your table, for example).


-- Jon Seeley
DotNetNuke Modules
Custom DotNetNuke and .NET Development
http://www.seeleyware.com
 
New Post
9/5/2008 6:04 PM
 

Here's a post that I found helpful in the past to prevent people from double-clicking the button client-side and causing the Submit to fire twice.

http://www.abstraction.net/content/articles/preventing%20double%20form%20submit%20in%20asp.net.htm

Without seeing the rest of your code it's hard to tell what may be causing it.

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Button click handle inserting 2 records instead of 1 record into SQLButton click handle inserting 2 records instead of 1 record into SQL


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out