Discussion:
Problem updating Gridview record
(too old to reply)
Clark
2007-11-28 12:36:52 UTC
Permalink
I have a relational SQLExpress database where data from a GridView is
updated. The update command query looks like:

UPDATE [Readings] SET [Date]=@Date, [Reading]=@Reading, [User_ID]=@User_ID,
[Category_ID]=@Category_ID, [ItemsTracked_ID]=@ItemsTracked_ID WHERE
[ReadingsID]=@ReadingsID

The Category_ID and ItemsTracked_ID are the foreign keys from the Categories
and ItemsTracked tables that are displayed in the Readings table, and the
parameters are set to be the Selected Value of the Gridview.

When the gridview shows all the fields, including the Category_ID and
Items_TrackedID, and a user clicks the edit button to change a date or a
reading, and then clicks the Update button, everything works fine, the
record is updated.

But I dont want the user to see the Category_ID or the ItemsTracked_ID in
the gridview because those are not fields they should be trying to modify.
So I click the little expander arrow in the Gridview, Choose Edit Columns,
Choose (for example) the Category_ID column and set it Visible behavior to
False.

This causes the Category_ID field not to show when viewed in browser which
is what I want, but then when a record is selected and an update is
attempted, it fails saying "Cannot insert the value Null into Categories_ID"

What is the solution that would allow an update to work without the
Category_ID being visible in the Gridview?

Thanks in advance ---
--
Clark
CHO, HomePage Doctor
www.homepagedoctor.com/ExpressionTutorials/Tutorials.htm
-------------------------------------------------------------------------------------------------
v***@prcvap.microsoft.com
2007-11-30 05:42:34 UTC
Permalink
Clark
2007-12-01 03:53:11 UTC
Permalink
Yes, thank you for the assistance. I should have figured that out myself !
--
Clark
CHO, HomePage Doctor
www.homepagedoctor.com/ExpressionTutorials/Tutorials.htm
-------------------------------------------------------------------------------------------------
Hello Clark,
Category_ID is invisible in your GridView. Thereby, ASP.net doesn¡¯t fill
its value into Category_ID field when updating. This results you get a
Null exception.
It seems Category_ID is not necessary in your business logic. My
suggestion is you have to remove it from your update command.
After that, I think your GridView will work fine again.
Hope this helps. Please feel free to update here again, if there is
anything unclear. It¡¯s my pleasure to assist you.
Have a great day,
Best regards,
Microsoft Online Support
Microsoft Global Technical Support Center
Get Secure! - www.microsoft.com/security
=====================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
v***@prcvap.microsoft.com
2007-12-03 07:10:28 UTC
Permalink
Loading...