devxlogo

Sending Null Values to a Required Field

Sending Null Values to a Required Field

Question:

When I try to send some information to an access database through ASP, I get the following error:

[Microsoft][ODBC Microsoft Access 97 Driver] Field 'tablename.class'
can't be a zero-length string.

This is the code from my page:

Set conn = Server.CreateObject("ADODB.Connection") data_source = "DBQ=" & Server.MapPath("filename.mdb") conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & data_sourceDefine strSQLconn.Execute strSQLconn.Close Set conn = Nothing 

Can you tell me what I’m doing wrong?

Answer:

You are getting this error because you are trying to create a record in a table where one or more of the fields (in your case the field ‘Class’) is a required field. That is, within Access, in the Table Design window, the ‘Allow Zero Length’ property for the field has been set to ‘No.’

There are two ways to solve this problem. First, think about whether you would like to have a record in which the field ‘Class’ will be empty, or null. If that is OK, open the Access Database, and go to the Table in Design mode. Then, navigate to the field and, down in the bottom, choose ‘Yes’ for ‘Allow Zero Length’. Save your table and your existing code will start working.

If you think the field Class should never be empty or null, then adjust your interface code to make sure you or your user always fills in a valid value before updating the data.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist