Solved

rdoResultset and Null Values

Posted on 1998-09-21
5
746 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
[X]
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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

707 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