Solved

ADO: Field cannot be a zero-length string

Posted on 2001-07-11
9
872 Views
Last Modified: 2007-11-27
I'm using ADO to create a recordset (adoTemp) from my existed database (called myTable). Anytime adding a null value to one of my string Field (DeviceName), I got an runtime error:

-214721887 : Field 'myTable.DeviceName' cannot be a zero length.


Here is my code:
Command1_Click()
   Dim adoTemp as ADODB.Recordset
   Dim strSQL as String
   Dim intDeviceID as Integer
   Dim strDeviceName as String

   strSQL = "Select * From myTable"
   set adoTemp = new ADODB.Recordset
   adoTemp.Open strSQL, myConnection, adOpenKeyset, adLockOptimistic, adCmdText

   .........
   intDeviceID = 1
   strDeviceName = ""

   adoTemp.AddNew
   adoTemp("DeviceID") =intDeviceID
   adoTemp("DeviceName") = strDeviceName
   adoTemp.Update
End Sub


Could anyone helps me solve this problem? [DeviceName] sometimes has a null value


Thanks in advance
nguyenn
0
Comment
Question by:nguyenn
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:John844
ID: 6274479
null and zero length string are two different things
database can allow nulls without allowing zero length strings for this field.
0
 
LVL 7

Expert Comment

by:John844
ID: 6274484
try changing
  adoTemp("DeviceName") = strDeviceName

to
  if strDeviceName = "" then
    'do nothing so null will go into field
  else
    adoTemp("DeviceName") = strDeviceName
  end if
0
 
LVL 7

Accepted Solution

by:
John844 earned 100 total points
ID: 6274494
if you need to update the field at some point, use similar logic to update field to vbNull if the string is ""
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 1

Author Comment

by:nguyenn
ID: 6274500
Hi John

But it doesnt solve problem when I update [DeviceName] to a null value
0
 
LVL 7

Expert Comment

by:John844
ID: 6274511
anothir way to allow zero length string is to go into design mode of your table.  click on the field in question.  at the bottom left corner of your window there will be a item "Allow Zero Length" = No.  Change this to Yes.  This will allow your existing code to be used, but it will not put a null into the field, it will be a zero length string like "".

Hope some of this helps you solve your current problem.
John
0
 
LVL 1

Author Comment

by:nguyenn
ID: 6274512
Thanks a bunch John, it helps me out

Have a nice day :)
0
 
LVL 20

Expert Comment

by:hes
ID: 6274518
How is DeviceName defined in the database table. Is it defined to allow zero length.
0
 
LVL 1

Author Comment

by:nguyenn
ID: 6274623
Hi Hes,

You're right, I didnt set allow zero lenght to Yes in the database.

Thanks for mention it
nguyenn
0
 
LVL 20

Expert Comment

by:hes
ID: 6274908
Glad you got it solved,
John and I were typing that at the same time :)
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

809 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