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

x
?
Solved

DBNull.Value to table adapter

Posted on 2009-02-19
9
Medium Priority
?
1,445 Views
Last Modified: 2012-05-06
How do I pass a DBNull.Value to a table adapter?

If a bookID is null, I want to send the null value to the table adapter. If I use DBNull.Value, as I do with ado.net, it errors that it wants a numeric value. How is this done? I must be able to save a null value.

thanks!
0
Comment
Question by:Starr Duskk
  • 4
  • 2
7 Comments
 
LVL 8

Expert Comment

by:Wikkard
ID: 23687222
Check the table adapter definition to see if you have marked that field as nullable.  
As long as the schema will allow it you should be able to set it to dbnull.value.
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 23687444
yes, allowdbnull is true and the default value is dbnull.
How do I save a dbnull value? How do I pass it in?
because this doesn't work.
myAdapter.UpdateBook(bookName,DBNull.Value)
it says value of type dbnull cannot be converted to integer.
 
0
 
LVL 8

Expert Comment

by:Wikkard
ID: 23687497
I think you should use nullable types.  http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx
Change the integer in your UpdateBook table adapter method to an int?
The you can pass the null values and check if a null value has been set.
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 2

Author Comment

by:Starr Duskk
ID: 23689266
It's already a System.Int32
I assign a combo box a value of -1 if it's not selected. So if it's -1, I need to pass a null value to the table.
I don't want to check if the value is null, because it's not. It's -1. I want to check if it's -1, and then pass a null value to the update method of it is null.
Can't someone please tell me how to pass a null value to a table adapter?
thanks.
 
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 2000 total points
ID: 23762168
why dont you do it this way, pass -1 to the table adapter and in the database sql check if the value is -1 then update null

NullIf(columnname, -1)

Nullif will return null if the value is -1
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 23770855
Beautiful. Thanks so much. And thanks WhackaMod too!
 
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 31549023
thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

831 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