Solved

rdoResultset and Null Values

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

20 Experts available now in Live!

Get 1:1 Help Now