Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

$4.95 Windows Hosting at Webhost4life.com
  Ads  
Engage Software - Training Partner for DotNetNuke
 


  Sponsors  

Meet Our Sponsors

MaximumASP
SourceGear - Tools for Developers
.: CounterSoft :.
telerik
ExactTarget email software solutions
Merak Mail Server
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! ( Pr...  Button click handle inserting 2 records instead of 1 record into SQL
Previous Previous
 
Next Next
New Post 9/5/2008 11:55 AM
Unresolved
User is offline mldardy
1 posts
10th Ranked


Button click handle inserting 2 records instead of 1 record into SQL 

 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 12:34 PM
User is offline Fooberichu
467 posts
www.seeleyware.com
8th Ranked


Re: Button click handle inserting 2 records instead of 1 record into SQL 

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).


-- Fooberichu
http://www.seeleyware.com
 
New Post 9/5/2008 4:04 PM
User is offline Keith Adler
55 posts
10th Ranked


Re: Button click handle inserting 2 records instead of 1 record into SQL 

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 Previous
 
Next Next
  Forum  General DotNetN...  Extend It! ( Pr...  Button click handle inserting 2 records instead of 1 record into SQL
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, 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 DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


DNNSpired.com
Inspired to extend DotNetNuke®, everyday.
www.DNNSpired.com
TMA Resources
TMA Resources is a software company providing eBusiness solutions for the Association market.
www.tmaresources.com
DotNetNuke Hosting Provider UK
UK leading DotNetNuke Hosting provider. Owned and operated by a Microsoft Gold Certified Partner.
www.DNN-Portals.co.uk

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP