|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GridView Update Not WorkingHello. 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? 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 (waw***@online.microsoft.com, 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. 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)" Show quoteHide quote "Walter Wang [MSFT]" wrote: > 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 (waw***@online.microsoft.com, 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. > > 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 (waw***@online.microsoft.com, 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.
Using ASP.NET 2.0's ImageMap Control
Treeview Styles Aren't working How to hide the "Edit" link in DetailsView via code? asp.net 2 report problem with 3-tier design White strip showing up between two imagemaps ASP.Net 2.0 Validation Groups & IValidator Controls. ASP code UserControls in a different directory Authentication in ASP.NET 2.0 create webcontrols in aspx or aspx.cs |
|||||||||||||||||||||||