Microsoft KB Archive/280514

= How To Use AppendChunk and GetChunk with NText Columns in a SQL Server CE Database =

Article ID: 280514

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft SQL Server 2000 Windows CE Edition

-



This article was previously published under Q280514



SUMMARY
This article contains a code sample that uses the the Microsoft ActiveX Data Objects for Windows CE (ADOCE) 3.1 AppendChunk and GetChunk methods against NText columns in a SQL Server CE database.

The code sample illustrates the creation of a sample database and table with an NText column and then adds a record to the table. The ADOCE AppendChunk method is then used to populate an NText column. Finally, the sample retrieves a portion of the data from the column by using the GetChunk method and displays the data in a message box.



MORE INFORMATION
 Create a new form in a Microsoft eMbedded Visual Basic (eVB) application, and then add a command button to the form. Reference the following libraries in your project:  Microsoft CE SQL Server Control 1.0

 Microsoft CE ADOCE Control 3.1

 Microsoft CE ADO Extensions 3.1 for DDL

  Type or paste the following code into the Click event of the command button: Option Explicit

Private Sub cmd01_Click

On Error Resume Next Dim cn As ADOCE.Connection Dim strConn As String Dim rs As ADOCE.Recordset Dim Cat As ADOXCE.Catalog Dim Notesfld, vData, vDisplay Dim j   Const adCmdTableDirect = 512 Const adOpenKeyset = 1 Const adLockOptimistic = 3 Set cn = CreateObject(&quot;adoce.connection.3.1&quot;) Set rs = CreateObject(&quot;adoce.recordset.3.1&quot;) 'Create a sample database Set Cat = CreateObject(&quot;ADOXCE.Catalog.3.1&quot;) Cat.Create &quot;Provider=Microsoft.SQLSERVER.OLEDB.CE.1.0;&quot; & _ &quot;Data source=\AppendChunk.sdf&quot;

Set Cat = Nothing strConn = &quot;Provider=microsoft.sqlserver.oledb.ce.1.0;&quot; & _ &quot;Data Source=\AppendChunk.sdf;&quot; cn.Open strConn cn.Execute &quot;Create Table Employees (EmpName NVarchar(30), Notes ntext)&quot; rs.Open &quot;Employees&quot;, cn, adOpenKeyset, adLockOptimistic, adCmdTableDirect ' Assign the 'Notes' field to a variable Set Notesfld = rs(&quot;Notes&quot;) rs.AddNew rs.Fields(&quot;EmpName&quot;) = &quot;Bill&quot; ' Example data to insert into the 'Notes' field vData = &quot;This is an example to show AppendChunk / GetChunk usage. &quot; ' Append the data in vData to the 'Notes' field ' The first AppendChunk call on a Field object writes data to the field, overwriting any existing data. ' Subsequent AppendChunk calls add to existing data For j = 1 To 10 Notesfld.AppendChunk vData Next rs.Update ' Get the first 100 characters from the 'Notes' field vDisplay = Notesfld.GetChunk(100) MsgBox vDisplay rs.Close cn.Close Set rs = Nothing Set cn = Nothing

End Sub

</li></ol>

<div class="references_section">