Solved

rdoResultset and Null Values

Posted on 1998-09-21
5
715 Views
Last Modified: 2013-12-25
I made a Client-Server Application with VB 6.0 and SQL Server. I've build a rdoResultset and bound the fields to text fields on a form. One field is a date field(smalldatetime) on the SQL Server its Name is dtBirthday.
Now to the Problem:
Situation: In the current Resultset the dtBirthday field is not null and I see the Birthday in the bounded text field on the VB Form. Now I want to clear the Text field birthday on the form and save it with the command   rdo.updaterow  ! Now I always receive the error message Data Type conversion!
I read something about, that when a text field is cleared the text fields value is null, but when the updaterow command is executed VB will change the text fields value to an empty string, and so its clear why the error message apears!
Knows someone a answer to this problem?
(How can I assign a null value to this text filed and then update the row?)

Thanks very much
                  Mike
 
0
Comment
Question by:mkaufmann
5 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1496341
use this :

rdo("Field") = tbTextBox.Text & ""

tbTextBox.Text = rdo("Field") & ""
0
 

Author Comment

by:mkaufmann
ID: 1496342
It does not work!
I cant assign to the rdo control like this!   ( rdo("field") )

My Code looks now like this, but I always receive the message "Incorrect type for Parameter"

Private Sub edBirthday_Validate(Cancel As Boolean)
    Dim rsMemb As rdoResultset
     Set rsMemb = dtaMembers.Resultset
    rsMemb.Edit
    rsMemb("dtBirthday") = edBirthday.Text & ""
    edBirthday.Text = rsMemb("dtBirthday") & ""
End Sub

(dtaMembers is the RDO Object!)
0
 

Expert Comment

by:trillian30
ID: 1496343
Have you tried just setting the data field to null & the text box to an empty string.

Private Sub edBirthday_Validate(Cancel As Boolean)
    Dim rsMemb As rdoResultset
     Set rsMemb = dtaMembers.Resultset
    rsMemb.Edit
    rsMemb("dtBirthday") = null
    edBirthday.Text = rsMemb("dtBirthday") & ""
End Sub

.or if need be test if the text box contains an empty string & if it does set the data field to null.
0
 
LVL 2

Expert Comment

by:mkmccreary
ID: 1496344
Try this:

Private Sub edBirthday_Validate(Cancel As Boolean)
    Dim rsMemb As rdoResultset
    Set rsMemb = dtaMembers.Resultset
    rsMemb.Edit
    If edBirthday.Text = "" Then
         rsMemb("dtBirthday") = Null
    Else
         ' Make Sure Valid Date
         If IsDate(edBirthday.Text) then
             rsMemb("dtBirthday")=edBirthday.Text
         Else
             ' Do What Ever
         End If
    End If
    rsMemb.Update
    rsMemb.Refresh
    Set rsMemb = Nothing
End Sub

Might have to play with the Refresh method to get it to work properly.

Good Luck,
Martin

0
 
LVL 2

Accepted Solution

by:
vspeter earned 50 total points
ID: 1496345
Since the dtBirthday field is not null and the field is of type smalldatetime, regardless what happen, the update value has to be a valid date.

Your best chance is to have a valid dummy date like 31/12/xxxx (xxxx = maximum year that SQL Server can take). You can use it as your default date, therefore

1. prior to display it in your text box check to see if that is the dummy date then display an empty string

2. prior to execute the update statement, check to see if the text box contain a null or empty string, save the field with the dummy date.
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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

863 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