Answered by:
duplicate MS record

Question
-
User1908679259 posted
hi
i created register page with unique primry username field , when customer enter exsiting username
the register process will not complete and this error msg will appear
Server Error in '/WebSite1' Application.
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
Source Error:
Stack Trace:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[OleDbException (0x80004005): The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1006560 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +386 System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +227 System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +86 System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) +272 System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +676 System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +95 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +113 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4955
how can i write it when customer press register button with duplicate username???<!-- [OleDbException]: The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) at System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) at System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) at System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) at System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) [HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown. at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.register_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->
Sunday, March 6, 2011 5:41 AM
Answers
-
User1867929564 posted
refer this,
http://forums.asp.net/t/1314371.aspx- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 7, 2011 8:14 AM
All replies
-
User-821857111 posted
You can do a checkusing javascript/jquery to show the user that the name they have chosen has already been taken: http://www.mikesdotnetting.com/Article/99/Preventing-duplicate-User-Names-with-ASP.NET-and-jQuery
Just change the SqlConnection, SqlCommand etc to OleDbConnection, OleDbCommand
Sunday, March 6, 2011 10:52 AM -
User1052258516 posted
The simple method would be be on the submit button click event on the register page to query the database and search the customer table for an existing username...
string sql = string.Concat("SELECT COUNT(UserName) AS CountOf FROM Customer WHERE UserName = '", txtUserName.Text.Trim(), "';");
Then if either the number of records returned is > 0 you have a possible duplicate, inform the user that the user name is already taken and they must pick another (better yet make the customers email address the UserName).
FYI: I don't encourage the use of in-line SQL like above, it is just meant as a psudo-code example.
Sunday, March 6, 2011 10:57 AM -
User-821857111 posted
An even simpler way is to catch the exception and return a meaningful error message, and some people thnk this is the way to go, but I don't.
Sunday, March 6, 2011 1:36 PM -
User1867929564 posted
I agree with Mike last post.
Use try exception, find error code of this error message .
any problem ask.
and some people thnk this is the way to go, but I don't.
Can you explain mike,wht harm in this ?Monday, March 7, 2011 12:25 AM -
User-821857111 posted
Exceptions should only be raised in exceptional circumstances - ones you cannot control in code, such as the unavailability of a file or a SQL server.
Monday, March 7, 2011 12:57 AM -
User1867929564 posted
Thanks
Monday, March 7, 2011 1:00 AM -
User1908679259 posted
but i used formview ??
Monday, March 7, 2011 2:47 AM -
User1867929564 posted
refer this,
http://forums.asp.net/t/1314371.aspx- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 7, 2011 8:14 AM