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
Solved

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

Posted on 2014-10-24
2
745 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…

856 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