G
Guest
Hi,
I am using a compare validator in asp.net application(c# code). This Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED.
For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .
But it doesnt work i.e, when i enter a value(which already exists in the
database) in the text box & hit submit, the Validation summary DOESNT SHOW
ERROR MESSAGE.
Instead, I get the error as::
Server Error in '/NEW' Application.
Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert duplicate
key in object 'FormFields'. The statement has been terminated.
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.
RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE DATABASE,then THE
VALIDATION SUMMARY SHOULD SHOW ERROR.
My code is::
private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();
// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}
Any help is appreciated.
Thanks
I am using a compare validator in asp.net application(c# code). This Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED.
For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .
But it doesnt work i.e, when i enter a value(which already exists in the
database) in the text box & hit submit, the Validation summary DOESNT SHOW
ERROR MESSAGE.
Instead, I get the error as::
Server Error in '/NEW' Application.
Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert duplicate
key in object 'FormFields'. The statement has been terminated.
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.
RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE DATABASE,then THE
VALIDATION SUMMARY SHOULD SHOW ERROR.
My code is::
private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();
// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}
Any help is appreciated.
Thanks