Microsoft KB Archive/304168

= BUG: No Error Given in ADO When Saving or Marshalling Recordset with Non-Null Columns =

Article ID: 304168

Article Last Modified on 11/5/2003

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Data Access Components 2.8

-



This article was previously published under Q304168



SYMPTOMS
If you persist a recordset with empty values at non-nullable columns to an Extensible Markup Language (XML) file by using the Save Method of an ADO Recordset, incorrect data is saved, and no error occurs.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
  Create a table in Microsoft SQL Server by using the following script:

Note You can cut and paste the statements directly into the SQL Query Analyzer tool, the ISQL utility, or the OSQL utility. CREATE TABLE [dbo].[rctest] ( [myid] [int] IDENTITY (1, 1) NOT NULL, [mytext] [varchar] (255) NULL , [mynum] [int] NOT NULL , [mydate] [datetime] NOT NULL , [mytext2] [varchar] (255) NOT NULL ) GO                    In Microsoft Visual Basic, create a new Standard EXE project. Form1 is created by default. On the Project menu, click Components. From the list of available components, select Microsoft ADO Data Control 6.0(OLEDB) and Microsoft DataGrid Control 6.0(OLEDB). On the Project menu, click References. From the list of available references, select Microsoft ActiveX Data Objects 2.8 Library. Place a DataGrid control and a CommandButton control on Form1. Set the AllowAddNew property of the DataGrid to True.</li>  Paste the following code in the Declarations section of Form1:

Note You must change User ID=<UID> and password= to the correct values before you run this code. Make sure that <UID> has the appropriate permissions to perform this operation on the database. Option Explicit

Dim cn As New ADODB.Connection Dim rs1 As New ADODB.Recordset

Private Sub Form_Load cn.Open &quot;Provider=SQLOLEDB.1;Data Source= ;user id=<UID>;&quot; & _ &quot;Password= ;Initial catalog= &quot; rs1.CursorLocation = adUseClient rs1.Open &quot;Select * from rctest where 1 = 2&quot;, cn, _ adOpenStatic, adLockBatchOptimistic Set rs1.ActiveConnection = Nothing Set DataGrid1.DataSource = rs1 End Sub

Private Sub Command1_Click Dim stm As New ADODB.Stream Dim fld As ADODB.Field rs1.Save stm, adPersistXML stm.SaveToFile &quot;c:\temp\xmlnull.xml&quot;, adSaveCreateOverWrite rs1.Close rs1.Open stm Set DataGrid1.DataSource = rs1

While Not rs1.EOF For Each fld In rs1.Fields Debug.Print fld.Value Next rs1.MoveNext Wend End Sub </li> Run the project.</li> Add data to the Mytext column by using the grid. Add three more rows of data. Only enter data in the Mytext column for all rows entered.</li> Click Command1. Note that the Xmlnull.xml file is created in the C:\Temp folder. You can see that the schema is correct. That is, the required columns show the rs:maybenull='false' attribute. However, no data is saved for those required columns, which makes the data incorrect according to the schema. An error should occur at the Save method indicating that required data was not provided.

When the grid is populated, zeros are displayed for the integer fields (Mynum and Myid), #ERROR is displayed at the date field (Mydate), and an empty string is displayed at the Mytext columns.</li></ol>

Additional query words: xml empty string wrong invalid

Keywords: kbbug kbpending KB304168

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.