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

  • SEARCH
  • Home
  • 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 174599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:33:04+00:00 2026-05-11T13:33:04+00:00

If I bind GridView to SqlDataSource and also set AutoGenerateEditButton to true, and if

  • 0

If I bind GridView to SqlDataSource and also set AutoGenerateEditButton to true, and if I then try to update a field ( this field being a primary key in database ), then database should return an error and thus SqlException should be thrown?!

So why doesn’t page report an exception? Instead, all Gridview does is setting all fields in that row back to their original values.

When I executed same update statement with the following code, I got Cannot update identity column ‘EmployeeID’ exception, so I’m assuming Sql Server did report same error when GridView tried to update, but for some reason exception wasn’t raised:

        SqlConnection sc = new SqlConnection();         sc.ConnectionString = @'Data source=localhost; integrated security=sspi; initial catalog=northwind;';         SqlCommand sComand = new SqlCommand();          sComand.Connection = sc;         sComand.CommandText = 'update Employees set EmployeeId=100,FirstName='Suzy','+                     'LastName='Smile',City='Moon' where EmployeeId=1';         sc.Open();         int I = sComand.ExecuteNonQuery(); 

BTW – I tried with setting DataKeyNames=’EmployeeId’, but exception was still not raised

thanx

EDIT:
Hello,

Sorry for not replying sooner, but I haven’t noticed I got a reply.

Anyways, for some reason it’s working now, meaning GridView does report an exception. Thus I must’ve made some mistake in my code, but due to constant rewriting of my code I have no idea where would that mistake be. Sorry for wasting your time and thank you for helping me out

  • 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. 2026-05-11T13:33:05+00:00Added an answer on May 11, 2026 at 1:33 pm

    Looking at the error and your code. It appears to be a SQL Database Error and not an issue with the GridView.

    SQL does not allow updates to IDENTITY columns since they get generated by the database engine. In this case ‘EmployeeId’ is such a field.

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

Sidebar

Related Questions

If I bind GridView (via DataSourceID attribute) to SqlDataSource and set SelectCommand and UpdateCommand
If I bind GridView to SqlDataSource, then the first time page will be created,
I had Gridview bind sqldatasource and I had logins which see gridview and I
I bind a SQLDataSource to a GridView using GridView.DataBind() and these queries often take
Ok guys, so I read this: How to set SelectedValue of DropDownList in GridView
I need to bind GridView , I am using this code: ProductDBEntities db =
I'm trying to bind my GridView at runtime, but I'm also trying to avoid
I have a gridview that contains one linkbutton within itemtemplate. I bind this gridview
I am sorting a GridView bind to a ananymous type. protected void GridView1_Sorting(object sender,
I need to bind width property of the GridView column that is created dynamically

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.