Solved

rdoResultset and Null Values

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

734 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