[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to handle null values in GridView update?

Posted on 2006-05-19
6
Medium Priority
?
400 Views
Last Modified: 2010-05-18
Hello - I've been thrashing around trying to make update work on a GridView.

It works fine on the test record that has values in every field, but the update does not happen on another test record that is missing values in some fields (I'm testing e.AffectedRows, and it comes back as 0 in this instance)

Do you have to do something special to handle fields with missing values?

Thanks

Mark
0
Comment
Question by:mlagrange
  • 3
  • 3
6 Comments
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 16722251
You can use generic values to replace any null values and update using the generic values
0
 

Author Comment

by:mlagrange
ID: 16722300
ok, can you give me an example?

In this particular situation, I've got a lot of different data types; text and integer, but also date, currency, double, & binary

Thanks

Mark
0
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 16722401
Dim ValFromGrid As String = CType(myGridView.FindControl("MytextBoxfromMyGridView"), TextBox).Text.Trim()
If ValFromGrid .Length = 0 Then
valFromGrid="N/A"
'insert your gridviewupdate code here like normal

        End If

Of course You need to check for values before you do the update

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Accepted Solution

by:
Sammy Ageil earned 2000 total points
ID: 16722447
theres a complete walk through here explaining the gridview and updating it
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/GridViewEx11.asp
0
 

Author Comment

by:mlagrange
ID: 16730508
Well, in this situation, I can't put generic values in the fields; if they are empty, they need to be empty.

I think this is what I've seen referred to in a couple of ASP.NET 2.0 books as "the optimistic concurrency bug". I narrowed it down to some date fields (hire, termination, re-hire dates) that don't have default values, and since they are date fields, generic values wouldn't be practical.

I tried using the books' solution of adding a check for both the current and original values NOT NULL. I modified the generated Update statement from:
...AND [RehireDate] = ? AND...
to:
...AND ( RehireDate = ? OR RehireDate IS NULL AND @original_RehireDate IS NULL ) AND...

, but I'm getting an error message:
"Exception occurred: No value given for one or more required parameters."  

It's got OldValuesParameterFormatString="original_{0}"; I tried the test as:
OR [RehireDate] IS NULL AND ? IS NULL
and:
OR RehireDate IS NULL AND original_RehireDate IS NULL
and:
OR RehireDate IS NULL AND @original_RehireDate IS NULL
I still got the same error message...

The example was for a SqlDataSource, and I'm using an AccessDataSource; that might have something to do with it, but I doubt it.

Any ideas? Some problem in the syntax?

Thanks

Mark
 
0
 

Author Comment

by:mlagrange
ID: 16872051
Sorry it took me so long to accept your answer - that is a great article

Thanks

Mark
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question