Solved

Bindingsource set Current to NULL (byte) or (datetime) field type in Strongly Type Dataset

Posted on 2014-10-24
2
693 Views
Last Modified: 2014-11-14
Hi Guys,

Can someone please show me how I can set a  field value of byte or datetime type to Null using Bindingsource. I tried using this approach but it errors out but I do know this works if I was using a SQL Update statement using SQL command tableadapter UPDATE etc.

My current code below doesn't work and I would like to use the bindingsource approach:

              Dim dt As Nullable(Of DateTime) = Nothing
                        Dim cs As Nullable(Of Byte) = Nothing


                        Me.Validate()
                        Me.TestBindingSource.Current("mydate") = dt
                        Me.TestBindingSource.Current("mybytefield") = cs
                        Me.TestBindingSource.EndEdit()
                        Me.TestTableAdapter.Update(Me.TestDataSet.tblTest

Open in new window


Thank you for your help in advance
0
Comment
Question by:databarracks
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
Nothing is not the same thing as Null, so putting a variable that is nothing in a field does not work.

Here is how it would be done in straight ADO if we wanted to use a Nullable variable that is empty and assign a Null to a field. I am not sure it would work on a BindingSource however, because I do not use data binding in my code.

If dt.HasValue Then
	 Me.TestBindingSource.Current("mydate") = dt
Else
	 Me.TestBindingSource.Current("mydate") = DBNull.Value
End If

Open in new window

0
 

Author Comment

by:databarracks
Comment Utility
Hi Jacques,

Apologies for leaving this so late but your method did work
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now