Solved

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

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 37
Name Space error VS2015 1 35
Graph API & MS Apps 1 53
locate sql commands in C# visual studio Project 6 37
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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

713 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