Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated.http://forums.asp.net/t/1564726.aspx/1?Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Wed, 02 Jun 2010 22:11:17 -040015647263892722http://forums.asp.net/p/1564726/3892722.aspx/1?Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Hi&nbsp;guys, I'm getting this error code in a voting system which I made.</p> <p>&nbsp;</p> <p>&quot;Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated.&quot;</p> <p>&nbsp;</p> <p>It's good&nbsp;because it means I&nbsp;am stopping people from voting twice, however, I want to display an error message in the site, and I want to make this occurance user friendly, as I have no idea how this error will look when the website is live.</p> <p>&nbsp;</p> <p>Here is all of my code:</p> <p>&nbsp;</p> <pre class="prettyprint">Imports System.Data.Sql Imports System.Data.SqlClient Partial Class Vote Inherits System.Web.UI.Page Protected Sub PostAward_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PostAward.Click Dim currentUser As MembershipUser = Membership.GetUser() Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid) Dim connectionString As String = ConfigurationManager.ConnectionStrings(&quot;SecurityTutorialsConnectionString&quot;).ConnectionString Dim insertSql As String = &quot;INSERT INTO Awards (Award1, Award2, Award3, Award4, Award5, Award6, Award7, Award8, UserId) VALUES (@Award1, @Award2, @Award3, @Award4, @Award5, @Award6, @Award7, @Award8, @UserId)&quot; Using myConnection As New SqlConnection(connectionString) myConnection.Open() Dim myCommand As New SqlCommand(insertSql, myConnection) myCommand.Parameters.AddWithValue(&quot;@Award1&quot;, Award1.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award2&quot;, Award2.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award3&quot;, Award3.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award4&quot;, Award4.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award5&quot;, Award5.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award6&quot;, Award6.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award7&quot;, Award7.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award8&quot;, Award8.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@UserId&quot;, currentUserId) myCommand.ExecuteNonQuery() &lt;----- THIS IS WHERE THE ERROR POINTS WHEN DEBUGGING IS ON myConnection.Close() End Using Response.Redirect(&quot;Default.aspx&quot;) End Sub End Class</pre> <p>&nbsp;</p> <p>How will this error look when the website is live? How can I display a message to warn the user that he has already voted?</p> <p>&nbsp;</p> <p>Thanks,</p> <p>Mike</p> <p><br> &nbsp;</p> 2010-06-02T17:05:19-04:003892830http://forums.asp.net/p/1564726/3892830.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>This article explains error handling</p> <p><a href="http://msdn.microsoft.com/en-us/library/5b2yeyab(VS.71).aspx">http://msdn.microsoft.com/en-us/library/5b2yeyab(VS.71).aspx</a></p> 2010-06-02T17:51:24-04:003892843http://forums.asp.net/p/1564726/3892843.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Try a &quot;Try&quot;/&quot;Catch&quot; block. Put everything in your &quot;using&quot; area inside the&nbsp;&quot;Try&quot;, and inside the &quot;Catch ex As Exception&quot;, put your code for letting the user know&nbsp;they already voted. Make sense?&nbsp;</p> 2010-06-02T17:55:10-04:003892847http://forums.asp.net/p/1564726/3892847.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Thanks for the reply Draak, but&nbsp;I couldn't really find&nbsp;what&nbsp;I was looking for. I'm an amateur by the way, so it could be staring me in the face.</p> <p>&nbsp;</p> <p>Thanks,</p> <p>Mike&nbsp;</p> 2010-06-02T17:56:42-04:003892858http://forums.asp.net/p/1564726/3892858.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>&quot;Try a &quot;Try&quot;/&quot;Catch&quot; block. Put everything in your &quot;using&quot; area inside the&nbsp;&quot;Try&quot;, and inside the &quot;Catch ex As Exception&quot;, put your code for letting the user know&nbsp;they already voted. Make sense?&quot;</p> <p>&nbsp;</p> <p>That sort of makes sense. Could you explain how to construct it and why, so I can learn?</p> 2010-06-02T18:03:10-04:003892874http://forums.asp.net/p/1564726/3892874.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Here's the general syntax:</p> <pre class="prettyprint">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles Button1.Click Try Process.Start(&quot;http://www.microsoft.com&quot;) Catch ex As Exception MsgBox(&quot;Can't load Web page&quot; &amp; vbCrLf &amp; ex.Message) End Try End Sub</pre><br>If you are making a web app, instead of MsgBox just drop a Label on your page, and set it's Text property to a string that summarizes what the error is about in user-friendly terms. So, you'd have something like this: </pre><pre class="prettyprint">Catch ex As Exception Label1.Text = "You can't vote twice" End Try</pre><br> </pre></pre> 2010-06-02T18:12:17-04:003892876http://forums.asp.net/p/1564726/3892876.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>why allow exception to occur, when you can avoid it?</p> <p>Check if this userid already has vote in current table and then throw or show nice message on page saying <img src="http://forums.asp.net/tiny_mce/jscripts/tiny_mce/plugins/emotions/img/smiley-laughing.gif" alt="Laughing" title="Laughing" border="0"><br> </p> <p>'You cannot vote more than once!&quot;</p> <p><pre class="prettyprint">Protected Sub PostAward_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PostAward.Click Dim currentUser As MembershipUser = Membership.GetUser() Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid) Dim connectionString As String = ConfigurationManager.ConnectionStrings(&quot;SecurityTutorialsConnectionString&quot;).ConnectionString Dim insertSql As String = &quot;INSERT INTO Awards (Award1, Award2, Award3, Award4, Award5, Award6, Award7, Award8, UserId) VALUES (@Award1, @Award2, @Award3, @Award4, @Award5, @Award6, @Award7, @Award8, @UserId)&quot; try Using myConnection As New SqlConnection(connectionString) myConnection.Open() 'Check if user has already voted if hasvoted then lblmessage =&quot;You cannot vote more than once!&quot; exit sub end Dim myCommand As New SqlCommand(insertSql, myConnection) myCommand.Parameters.AddWithValue(&quot;@Award1&quot;, Award1.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award2&quot;, Award2.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award3&quot;, Award3.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award4&quot;, Award4.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award5&quot;, Award5.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award6&quot;, Award6.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award7&quot;, Award7.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award8&quot;, Award8.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@UserId&quot;, currentUserId) myCommand.ExecuteNonQuery() &lt;----- THIS IS WHERE THE ERROR POINTS WHEN DEBUGGING IS ON myConnection.Close() End Using Response.Redirect(&quot;Default.aspx&quot;) catch throw ex; end try End Sub function hasvoted() as boolean 'code to check if that user id already has record and return true or false end function</pre><br> <br> </p> 2010-06-02T18:12:30-04:003892881http://forums.asp.net/p/1564726/3892881.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Yes sir!</p> <p>&nbsp;</p> <p>This is what it would look like with your code:</p> <p>&nbsp;</p> <pre class="prettyprint">Using myConnection As New SqlConnection(connectionString) Dim myCommand As New SqlComand(insertSql, myConnection) 'blah blah blah all the parameters junk Try myConnection.Open() myCommand.ExecuteNonQuery() myConnection.Close() Catch ex As Exception ' display message End Try End Using</pre> <p><br> So I rearranged a little, but it's probably better to put it in this order (it&nbsp;would all execute the same).</p> <p>Okay, so the point of try/catch is obviously to catch exception. The program &quot;tries&quot; to execute all code in the &quot;Try&quot; part, and anything that goes wrong in the system throws an exception. If an exception is thrown at any point during the code in the &quot;Try&quot; part, then the &quot;Catch&quot; part is executed and the exception is stored in ex. Usually, ex is converted to a string and displayed in the &quot;Catch&quot; part to tell the user what the problem is. You don't see exceptions unless you do a try/catch and show the exception, but things just don't work right and you won't know without this.</p> <p>So in your new code's case, the exception can be anything about myConnection.Open() failing, myCommand.ExecuteNonQuery() failing, or myConnection.Close() failing (probably one of the first two). So I put myConnection.Open() inside in case something happens with the connection. But then there's no way to know which is the error from - connection or command...so if you want, put .Open() before Try and .Close() after End Try. You can do this because I guess we're really only worried about the ExecuteNonQuery working or not.</p> <p>SO, if an exception is thrown (ExecuteNonQuery) fails in some way, then the Catch part executes, and this is where you can put whatever you want to show the user they've already voted, or just redirect them, or whatever.</p> <p>&nbsp;</p> <p>Does this make sense?</p> 2010-06-02T18:13:37-04:003892894http://forums.asp.net/p/1564726/3892894.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>And if you want to filter only for SQL-related errors, just replace Exception with SqlException in your Catch block. This way you'll be sure that your error message actually matches the error.</p> <p><a href="http://msdn.microsoft.com/en-us/library/686y883x(v=VS.100).aspx">http://msdn.microsoft.com/en-us/library/686y883x(v=VS.100).aspx</a></p> 2010-06-02T18:17:36-04:003892897http://forums.asp.net/p/1564726/3892897.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Wow thanks, Draak,&nbsp;rsw20 and hoodedperson 70, I appreciate the effort you have put in!</p> <p>&nbsp;</p> <p>I actually understand this now, thanks for the extended explaination guys. </p> <p>I suppose my site is now complete!! Does anyone know any good UK hosts for asp.net?</p> <p>&nbsp;</p> <p>Thanks again,</p> <p>Mike</p> 2010-06-02T18:19:16-04:003892900http://forums.asp.net/p/1564726/3892900.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Uk hosting site<br> </p> <pre id="line1">http://www.pixelinternet.co.uk/ref/wizhosting/9b855f76.php</pre> <p><br> </p> 2010-06-02T18:22:51-04:003892910http://forums.asp.net/p/1564726/3892910.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>You're welcome. Please remember to mark replies as answers if they help. Thanks.</p> 2010-06-02T18:30:59-04:003892916http://forums.asp.net/p/1564726/3892916.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Congrats! Good to hear. I can't say I know any since&nbsp;I'm in the States, but let us know if you&nbsp;need anything else&nbsp;</p> 2010-06-02T18:33:30-04:003892927http://forums.asp.net/p/1564726/3892927.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>hooded, where you've written&nbsp;&quot;display message&quot;&nbsp;can I just put &quot;lblmessage&nbsp;=<span>&quot;You&nbsp;cannot&nbsp;vote&nbsp;more&nbsp;than&nbsp;once!&quot;</span>&quot; or&nbsp; &quot;Label1.Text&nbsp;=&nbsp;<span>&quot;You&nbsp;can't&nbsp;vote&nbsp;twice&quot;</span><span></span>&quot; like what Draak and rsw20 said?</p> 2010-06-02T18:38:07-04:003892948http://forums.asp.net/p/1564726/3892948.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Yep, that's exactly what I meant.</p> <p>&nbsp;</p> <p>And did you put the .Open() &amp; .Close() outside of the whole Try block? I think you should <img title="Foot in mouth" border="0" alt="Foot in mouth" src="http://forums.asp.net/tiny_mce/jscripts/tiny_mce/plugins/emotions/img/smiley-foot-in-mouth.gif">&nbsp;</p> 2010-06-02T18:43:46-04:003892966http://forums.asp.net/p/1564726/3892966.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>that is a typo use lblmessage.text or labelname.text<br> </p> 2010-06-02T18:47:26-04:003892975http://forums.asp.net/p/1564726/3892975.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <pre class="prettyprint">Protected Sub PostAward_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PostAward.Click Dim currentUser As MembershipUser = Membership.GetUser() Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid) Dim connectionString As String = ConfigurationManager.ConnectionStrings(&quot;SecurityTutorialsConnectionString&quot;).ConnectionString Dim insertSql As String = &quot;INSERT INTO Awards (Award1, Award2, Award3, Award4, Award5, Award6, Award7, Award8, UserId) VALUES (@Award1, @Award2, @Award3, @Award4, @Award5, @Award6, @Award7, @Award8, @UserId)&quot; Using myConnection As New SqlConnection(connectionString) Dim myCommand As New SqlCommand(insertSql, myConnection) myCommand.Parameters.AddWithValue(&quot;@Award1&quot;, Award1.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award2&quot;, Award2.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award3&quot;, Award3.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award4&quot;, Award4.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award5&quot;, Award5.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award6&quot;, Award6.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award7&quot;, Award7.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@Award8&quot;, Award8.Text.Trim()) myCommand.Parameters.AddWithValue(&quot;@UserId&quot;, currentUserId) Try myConnection.Open() myCommand.ExecuteNonQuery() myConnection.Close() Catch ex As Exception End Try lblmessage = &quot;You cannot vote more than once!&quot; End Using Response.Redirect(&quot;Default.aspx&quot;) End Sub</pre> <p><br> Do you mean like that?</p> <p>&nbsp;</p> <p>For some reason, I don't see the message, it just sends me back to default.aspx</p> <p>&nbsp;</p> <p>&nbsp;</p> 2010-06-02T18:53:51-04:003892983http://forums.asp.net/p/1564726/3892983.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p>Real fast - put myConnection.Open() before the &quot;Try&quot;, and put myConnection.Close() right before &quot;End Using&quot;. </p> <p>&nbsp;</p> <p>You need to put lblmessage=&quot;You cannot vote more than once!&quot; on the line right after &quot;Catch ex As Exception&quot; (and before &quot;End Try&quot;). </p> <p>But quick question - do you want the page to always redirect to Default.aspx? Or only if successful vote? Or after so long the error&nbsp;message is displayed?</p> 2010-06-02T18:58:21-04:003892986http://forums.asp.net/p/1564726/3892986.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p></p> <pre class="prettyprint">Catch ex As exception lblMessage.Text = &quot;Message&quot; 'use .text to display end try</pre> <p><br> move lblMessage before end try and after catch</p> <p><br> If you write code this way you will always display &quot;You cannot vote more than once&quot; for other exceptions/errors also. <br> So i would suggest you to avoid coding in that fashion.</p> 2010-06-02T18:59:06-04:003892992http://forums.asp.net/p/1564726/3892992.aspx/1?Re+Violation+of+PRIMARY+KEY+constraint+PK_Awards+Cannot+insert+duplicate+key+in+object+dbo+Awards+The+statement+has+been+terminated+Re: Violation of PRIMARY KEY constraint 'PK_Awards'. Cannot insert duplicate key in object 'dbo.Awards'. The statement has been terminated. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>rsw20</h4> <p>move lblMessage before end try and after catch</p> &lt;div class=dp-highlighter&gt; &lt;div class=bar&gt; &lt;div class=tools&gt;<a href="#">view plain</a><a href="#">copy to clipboard</a><a href="#">print</a><a href="#">?</a>&lt;/div&gt;&lt;/div&gt; <ol class="dp-c"> <li class="alt"><span><span>Catch&nbsp;ex&nbsp;As&nbsp;exception &nbsp;&nbsp;</span></span> </li><li><span>&nbsp;lblMessage.Text&nbsp;=&nbsp;</span><span class="string">&quot;Message&quot;</span><span>&nbsp;'use&nbsp;.text&nbsp;to&nbsp;display &nbsp;&nbsp;</span> </li><li class="alt"><span>end&nbsp;</span><span class="keyword">try</span><span>&lt;BR&gt;&lt;BR&gt;If&nbsp;you&nbsp;write&nbsp;code&nbsp;</span><span class="keyword">this</span><span>&nbsp;way&nbsp;you&nbsp;will&nbsp;always&nbsp;display&nbsp;</span><span class="string">&quot;You&nbsp;cannot&nbsp;vote&nbsp;more&nbsp;than&nbsp;once&quot;</span><span>&nbsp;</span><span class="keyword">for</span><span>&nbsp;other&nbsp;exceptions/errors&nbsp;also.&nbsp;&lt;BR&gt;So&nbsp;i&nbsp;would&nbsp;suggest&nbsp;you&nbsp;to&nbsp;avoid&nbsp;coding&nbsp;</span><span class="keyword">in</span><span>&nbsp;that&nbsp;fashion.&lt;BR&gt;&nbsp;&nbsp;</span></li></ol> &lt;/div&gt;<pre class="prettyprint">Catch ex As exception lblMessage.Text = &quot;Message&quot; 'use .text to display end try<br> <br> If you write code this way you will always display &quot;You cannot vote more than once&quot; for other exceptions/errors also. <br> So i would suggest you to avoid coding in that fashion</pre> <p>&nbsp;</p> <p></p> </blockquote> <p></p> <p>&nbsp;</p> <p>Oops, yeah use&nbsp;lblMessage.Text</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>As for displaying&nbsp;the message for other exceptions...it'll only display&nbsp;an exception if ExecuteNonQuery fails, right? (if .Open() &amp; .Close() are taken out of the Try block)&nbsp;</p> 2010-06-02T19:03:47-04:00