Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5967469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:56:56+00:00 2026-05-22T19:56:56+00:00

I am using a gridview i that adding the row with text box and

  • 0

I am using a gridview i that adding the row with text box and adding the data which is successfully done.. But when i am update a field Email it is showing the error.. Violation of UNIQUE KEY constraint while updating field

function: Update_U_Anonymoususerdetails

int InsId=0, UserId=0,UserInstLink=0,UserCreditRecord=0;
                SqlConnection Cn = new SqlConnection(Conn);
                Cn.Open();
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    Label Id = GridView1.Rows[i].FindControl("lblId") as Label;
                    TextBox Name = GridView1.Rows[i].FindControl("txtName") as TextBox;
                    TextBox MName = GridView1.Rows[i].FindControl("txtMName") as TextBox;
                    TextBox LName = GridView1.Rows[i].FindControl("txtLName") as TextBox;
                    TextBox Degree = GridView1.Rows[i].FindControl("txtDegree") as TextBox;
                    TextBox Title = GridView1.Rows[i].FindControl("txtTitle") as TextBox;
                    TextBox Email = GridView1.Rows[i].FindControl("txtEmail") as TextBox;
                    TextBox Institution = GridView1.Rows[i].FindControl("txtInstitution") as TextBox;
                    if (Name.Text.Trim() != null && Name.Text.Trim() !="")
                    {
                        int AId = 0;
                        if (Id != null)
                            AId = Convert.ToInt32(Id.Text);
                        else
                            AId = 0;                       
                        SqlCommand Cmd = new SqlCommand("UpdateOtherAuthors", Cn);
                        Cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter InID = new SqlParameter("@uiID", SqlDbType.Int);                      
                        InID.Direction = ParameterDirection.Output;
                        Cmd.Parameters.Add(InID);
                        Cmd.Parameters.AddWithValue("@Name", Name.Text);
                        Cmd.Parameters.AddWithValue("@MName", MName.Text);
                        Cmd.Parameters.AddWithValue("@LName", LName.Text);
                        Cmd.Parameters.AddWithValue("@Degree", Degree.Text);
                        Cmd.Parameters.AddWithValue("@Title", Title.Text);
                        Cmd.Parameters.AddWithValue("@Email", Email.Text);
                        Cmd.Parameters.AddWithValue("@Institution", Institution.Text);
                        Cmd.Parameters.AddWithValue("@Id", AId);
                        Cmd.Parameters.AddWithValue("@CaseId", CaseId);                        
                        Cmd.ExecuteNonQuery();
                        UserId = int.Parse(Cmd.Parameters["@uiID"].Value.ToString());//getting error in this line first

                    }
                    if (Institution.Text.Trim() != null && Institution.Text.Trim() != "")
                    {

                       SqlCommand cmd = new SqlCommand("AddInstitution", Cn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter oParam = new SqlParameter("@Institution", Institution.Text.ToString());
                        SqlParameter InID = new SqlParameter("@InID",SqlDbType.Int);
                        oParam.Direction = ParameterDirection.Input;
                        InID.Direction = ParameterDirection.Output;
                        cmd.Parameters.Add(oParam);
                        cmd.Parameters.Add(InID);
                        cmd.ExecuteNonQuery();
                        InsId = int.Parse(cmd.Parameters["@InID"].Value.ToString());

                    }
                   UserInstLink= UserInstutionLink(UserId, InsId);// I am getting the error in this line
                   UserCreditRecord = UserCreditRecordID(UserInstLink, Name.Text, MName.Text, LName.Text, Degree.Text, Title.Text);
                   AssignContentManagementPrivileges(UserId,CaseId);
                   CreateCaseCredits(InsId, CaseId, UserCreditRecord);

                }
                Cn.Close();


store procedure i am using

CREATE PROCEDURE [dbo].[UpdateOtherAuthors]

(
@Name nvarchar(50),
@MName nvarchar(50),
@LName nvarchar(50),
@Degree nvarchar(50),
@Title nvarchar(50),
@Email nvarchar(50),
@Institution nvarchar(50),
@Id int,
@CaseId int,
@uiID int output

)

AS BEGIN
Declare @SameId nvarchar(50)
if(@Id='0')
begin
INSERT INTO tbl_AuthorDetails VALUES(@Name,@Degree,@Title,@Email,@Institution,@CaseId,@LName,@MName)
    Select @Id=COUNT(Email) from [User] where Email=@Email
    if(@Id=0)
    begin
    exec CreateOtherAuthorsAccount @Name,@LName,@MName,@Degree,@Email
    end
end
else
begin

set @SameId=(Select (Email) from  tbl_AuthorDetails where Id=@Id)
if(@SameId = @Email)
  Update  tbl_AuthorDetails set Name=@Name,Degree=@Degree,Title=@Title,Email=@Email,Institution=@Institution,LName=@LName,MName=@MName where Id=@Id
else
 begin
    INSERT INTO tbl_AuthorDetails VALUES(@Name,@Degree,@Title,@Email,@Institution,@CaseId,@LName,@MName)
    Update  tbl_AuthorDetails set  CaseId=NULL  where Id=@Id
    exec CreateOtherAuthorsAccount @Name,@LName,@MName,@Degree,@Email
    end
end

END
set @uiID= (Select ID from [User] where Email=@Email)  
RETURN @uiID

calling the function:

objGetBaseCase.Update_U_Anonymoususerdetails(GridView1, Convert.ToInt32(Request.QueryString[0])); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:56:57+00:00Added an answer on May 22, 2026 at 7:56 pm

    It is because a record with same email already exists in the database. And the database has a constraint on the email field that each entry in this field should be unique in the table you are inserting data into.

    EDIT: If this data is provided by a user, then you need to catch this exception and show a message to the user “A record with same email address already exists in the system.” And allow him/her to re-enter data for the email field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writting a simple prototype front end using a GridView that is populated via
I have a gridview that is using a LinqDataSource for it's datasource. I've added
I have a gridview that I have added a checkbox column using a templatefield
I am using paging on a GridView that is tied to a List<Employee> .
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I have a gridview in an update panel and am using a jQuery dialog
I have a GridView using LinqDataSource to populate data from table Tickets . The
I am using GridView in my application for populating datas. Is there any easy
Currentaly I am using a gridView and on RowCommand event of gridview the details
i want to display some information in a listview using the GridView. i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.