GridView Update Not Working

S

Saubz

Hello. I have a problem with my GridView not updating. I have a GridView
showing 4 fields from a database table. If all 4 of the fields have values
showing in the GridView, then using the automatically generated Edit button
on the GridView works just fine - the database updates. But if one of the
fields in the GridView is empty(representing a NULL value in the database)
then the Edit button does not Update the changes in the database - the page
posts back with the same data. I have the ConvertEmptyStringToNull="true"
property set in the <UpdateParameters> in my SqlDataSource. Is there
something else I am missing? Why won't this work?
 
W

Walter Wang [MSFT]

Hi,

From [3]: Using Parameter objects in the data source control's
UpdateParameters, InsertParameters, or DeleteParameters collections is
optional, you can use them to customize the values passed by the data-bound
control. You might create Parameter objects to strongly type the value or
to specify a default value if null is passed.

Parameter's ConvertEmptyStringToNull is true by default.

Are you using SqlDataSource with GridView? Normally GridView's Edit mode
and SqlDataSource should work out of the box, specifying UpdateParameters
is optional.

You can refer to [2] for sample code how to use SqlDataSource to update the
database. I've tested using a simple table (which has two nullable fields)
and it works correctly with the GridView.

So, would you please post your code here and let me take a look at it?
Thanks.


References:

[1] Using Parameters with the SqlDataSource Control
http://msdn2.microsoft.com/en-us/library/z72eefad.aspx

[2] Using Parameters with Data Source Controls
http://msdn2.microsoft.com/en-us/library/xt50s8kz.aspx

[3] How a Data Source Control Creates Parameters for Data-bound Fields
http://msdn2.microsoft.com/en-us/library/ms228051.aspx

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Saubz

Walter,

Thank you for your reply and the references. Here is the update command for
the data source. The first one is my original code, and the second one is a
fix that I figured out. The visual studio provided SQL command for
optimistic concurrency was not syntactically correct. I would like to know
if my working code is a preferred way or an accepted way of doing things.

------ORIGINAL CODE-------
UpdateCommand="
UPDATE [Checks]
SET [IBS] = @IBS,
[Branch] = @Branch,
[CheckNumber] = @CheckNumber,
[Date] = @Date,
[Amount] = @Amount,
[Payee] = @Payee,
[Purpose] = @Purpose,
[Void] = @Void,
[OutTo] = @OutTo,
[Borrower] = @Borrower,
[Loan] = @Loan,
[Posted] = @Posted
WHERE [ID] = @original_ID AND
[IBS] = @original_IBS AND
[Branch] = @original_Branch AND
[CheckNumber] = @original_CheckNumber AND
[Date] = @original_Date AND
[Amount] = @original_Amount AND
[Payee] = @original_Payee AND
[Purpose] = @original_Purpose AND
[Void] = @original_Void AND
[OutTo] = @original_OutTo AND
[Borrower] = @original_Borrower AND
[Loan] = @original_Loan AND
[Posted] = @original_Posted"

---------WORKING CODE-----------
UpdateCommand="
UPDATE [Checks]
SET [IBS] = @IBS,
[Branch] = @Branch,
[CheckNumber] = @CheckNumber,
[Date] = @Date,
[Amount] = @Amount,
[Payee] = @Payee,
[Purpose] = @Purpose,
[Void] = @Void,
[OutTo] = @OutTo,
[Borrower] = @Borrower,
[Loan] = @Loan,
[Posted] = @Posted
WHERE [ID] = @original_ID AND
[IBS] = @original_IBS AND
[Branch] = @original_Branch AND
[CheckNumber] = @original_CheckNumber AND
([Date] = @original_Date OR @original_Date IS NULL) AND
([Amount] = @original_Amount OR @original_Amount IS NULL) AND
([Payee] = @original_Payee OR @original_Payee IS NULL) AND
([Purpose] = @original_Purpose OR @original_Purpose IS NULL) AND
([Void] = @original_Void OR @original_Void IS NULL) AND
([OutTo] = @original_OutTo OR @original_OutTo IS NULL) AND
([Borrower] = @original_Borrower OR @original_Borrower IS NULL) AND
([Loan] = @original_Loan OR @original_Loan IS NULL) AND
([Posted] = @original_Posted OR @original_Posted IS NULL)"





Walter Wang said:
Hi,

From [3]: Using Parameter objects in the data source control's
UpdateParameters, InsertParameters, or DeleteParameters collections is
optional, you can use them to customize the values passed by the data-bound
control. You might create Parameter objects to strongly type the value or
to specify a default value if null is passed.

Parameter's ConvertEmptyStringToNull is true by default.

Are you using SqlDataSource with GridView? Normally GridView's Edit mode
and SqlDataSource should work out of the box, specifying UpdateParameters
is optional.

You can refer to [2] for sample code how to use SqlDataSource to update the
database. I've tested using a simple table (which has two nullable fields)
and it works correctly with the GridView.

So, would you please post your code here and let me take a look at it?
Thanks.


References:

[1] Using Parameters with the SqlDataSource Control
http://msdn2.microsoft.com/en-us/library/z72eefad.aspx

[2] Using Parameters with Data Source Controls
http://msdn2.microsoft.com/en-us/library/xt50s8kz.aspx

[3] How a Data Source Control Creates Parameters for Data-bound Fields
http://msdn2.microsoft.com/en-us/library/ms228051.aspx

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi,

Thanks for your update.

It turns out this is a know bug:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedbac
kID=93937

Your workaround should work; another workaround is to "SET ANSI_NULLS to
OFF".

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top