Solved

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

Posted on 2014-10-24
2
785 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Web Add-in Where is Visual Basic used 9 69
SQL Time out only from one specific computer client 15 49
What is needed to become a DBA? 7 46
vb.net code 9 25
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…

738 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