BUG: VB Dynasets Incorrectly Bypass Defaults on SQL ServerLast reviewed: June 21, 1995Article ID: Q101522 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SYMPTOMSWhen inserting a row into a SQL Data Source using dynasets, you may see one of the following behaviors:
CAUSEOn 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.
STATUSMicrosoft 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 ProblemThe 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.CloseIf 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |