Solved

rdoResultset and Null Values

Posted on 1998-09-21
5
731 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 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