Solved

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

Posted on 2014-10-24
2
708 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
ID: 40403507
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
ID: 40442086
Hi Jacques,

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

21 Experts available now in Live!

Get 1:1 Help Now