BUG: VB Dynasets Incorrectly Bypass Defaults on SQL Server

Last reviewed: June 21, 1995
Article ID: Q101522
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, version 3.0

SYMPTOMS

When inserting a row into a SQL Data Source using dynasets, you may see one of the following behaviors:

  • The row is not inserted due to a NON-NULL integrity conflict.
  • The row is inserted but the default for a column is bypassed.

The behavior depends on the table definition (can it be made NULL or not) for the default-bound column. If default(s) exist on the table in SQL Server and the dynaset column corresponding to the default-bound column is not given a value before the insert, one the behaviors listed above will occur:

CAUSE

On the Update method for the Dynaset, the following SQL code is generated by Jet Engine used by both Microsoft Access and Visual Basic version 3.0:

   Insert into Customer (Name, City) values ("bob", NULL)

For example, look at the schema definition shown in the More Information section below. If the table definition is as in A, the Insert fails because it is an attempt to insert NULL into a non-null column. If the table definition is as in B, the Insert command inserts "bob" and Null into the table -- bypassing the default of "Seattle" for City

To correct the problem, the Jet Engine should construct the SQL Statement to enforce defaults:

   Insert into Customer (Name) values ("bob")

This would correctly insert "bob" and "Seattle" into the Customer table.

STATUS

Microsoft has confirmed this to be a bug in Visual Basic version 3.0. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Example to Reproduce Problem

The following example demonstrates this incorrect behavior:

// SQL Server schema definition

// A) City is defined 'non-nullable' for behavior (1) to manifest
   Create table Customer
   (Name char(30) not null , City char(30) not null)

// B) City is defined 'nullable' for behavior (2) to manifest
   Create table Customer
   (Name char(30) not null , City char(30) null)

   Create Unique Index Customer_ndx on Customer(name)
   Create Default city_default  as "Seattle"
   sp_bindefault city_default, 'table.city'

// VB Code to insert a new row into SQL Server
   Dim DS as Dynaset
   DS = DB.Createdynaset ("Customer")
   DS.AddNew
   DS("Name") = "bob"
// No code to set the value for 'City'
   DS.Update
   DS.Close

If the table definition for Customer is as in A, an attempt to insert a new row into SQL Server fails with the following message from SQL Server:

   Column 'Name' in table 'Customer' may not be NULL.

If the table definition for Customer is as in B, the row is inserted into SQL Server, but the default has been bypassed. The values "bob" and Null are inserted into the table


Additional reference words: buglist3.00 3.00 Access JET default update
KBCategory: kbinterop kbprg kbbuglist
KBSubcategory: APrgDataODBC



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.