ImportString method (DataWindows)
Description
Inserts data into a DataWindow control or DataStore from tab-separated, comma-separated,
or XML data in a string.

A separate method name is provided as an alternative syntax
for Web DataWindow components that cannot use overloaded methods.
Controls
DataWindow type |
Method applies to |
---|---|
PowerBuilder |
DataWindow control, DataWindowChild object, DataStore |
Web |
Server component |
Web ActiveX |
DataWindow control, DataWindowChild object |
Syntax
[PowerBuilder]
1 |
long <span>dwcontrol</span>.<span>ImportString</span> ( {saveastype <span>importtype</span>}, string <span>string</span> {, long <span>startrow </span>{, long <span>endrow</span> {,long <span>startcolumn</span> {, long <span>endcolumn </span>{, long <span>dwstartcolumn</span> } } } } } ) |
[Web DataWindow server component]
1 |
long <span>dwcontrol</span>.<span>ImportString </span> ( string <span>string</span> ) <br>long <span>dwcontrol</span>.<span>ImportStringEx </span> ( string <span>importtype</span>, string <span>string</span>, <br> long <span>startrow</span>, long <span>endrow</span>, long <span>startcolumn</span>, long <span>endcolumn</span>, <br> long <span>dwstartcolumn</span> ) |
[Web ActiveX]
1 |
number <span>dwcontrol</span>.<span>ImportString</span> ( number <span>importtype</span>, string <span>string,</span> number <span>startrow</span>, number<span> endrow</span>, number <span>startcolumn,</span> number <span>endcolumn</span>, number<span> dwstartcolumn</span> ) |
Argument |
Description |
---|---|
dwcontrol |
A reference to a DataWindow control or |
importtype (optional |
An enumerated value of the SaveAsType
If you want to generate an XML trace file, the XML! argument |
string |
A string from which you want to copy |
startrow |
The number of the first detail row in For default XML import, if startrow is For template XML import, if startrow is |
endrow |
The number of the last detail row in For default XML import, if endrow is For template XML import, if endrow is |
startcolumn (optional |
The number of the first column in the For default XML import, if startcolumn is This argument has no effect on template XML import. |
endcolumn (optional |
The number of the last column in the For default XML import, if endcolumn is This argument has no effect on template XML import. |
dwstartcolumn (optional |
The number of the first column in the |
Events
ImportString may trigger an ItemError event.
Return Values
Returns the number of rows that were imported if it succeeds
and one of the following negative integers if an error occurs:
-
-1
No rows or startrow value supplied is
greater than the number of rows in the string -
-3
Invalid argument
-
-4
Invalid input
-
-11
XML Parsing Error; XML parser libraries not found or XML not well
formed -
-12
XML Template does not exist or does not match the DataWindow
-
-13
Unsupported DataWindow style for import
-
-14
Error resolving DataWindow nesting
Usage
All the arguments of this function except string are
optional. You do not need to specify the importtype argument.
The string must be formatted in tab-separated or comma-separated columns
or in XML. For TXT and CSV files, the format of the string is the same
as if the data came from an ASCII file, and each line must end with a
carriage return and a newline character (~r~n). If the string has
four tab-separated columns, one line might look like for a tab-separated
string:
1 |
<span>col1_data</span>~t <span>col2_data</span>~t <span>col3_data</span>~t <span>col4_data</span>~r~n |
For a DataWindow control or DataStore, the string should consist
of rows of data. If the data includes column headings or row labels,
set the startrow and startcolumn arguments
to skip them. The datatypes and order of the DataWindow object’s
columns must match the columns of data in the string.
The startcolumn and endcolumn arguments
control the number of columns imported from the string and the number
of columns in the DataWindow that are affected. The dwstartcolumn argument
specifies the first DataWindow column to be affected. The following
formula calculates the last DataWindow to be affected.
1 |
<span>dwstartcolumn </span>+ ( <span>endcolumn</span> - <span>startcolumn </span>) |
If string data to be assigned to a single row and column has
multiple lines (indicated by line-ending characters in the import
string), you must quote the string data using ~”. Do not use single
quotes.
This example of a valid tab-separated import string assigns
multiline values to each row in column 2:
1 |
ls_s = & |
1 |
"1~t~"Mickey~r~nMinnie~r~nGoofy~" ~r~n" + & |
1 |
"2~t~"Susan~r~nMary~r~nMarie~" ~r~n" + & |
1 |
"3~t~"Chris~r~nBen~r~nMike~" ~r~n" + & |
1 |
"4~t~"Mott~r~nBarber~r~nPicard~" " |
If an XML or CSV column contains a leading double quote, it
is assumed to be part of the column value. A leading double quote
has to be closed to mark the end of an item.
ImportString does not support Crosstab DataWindow objects.
Examples
These statements copy all data in the string ls_Emp_Data
to the DataWindow control dw_employee starting at the first
column:
1 |
string ls_Emp_Data |
1 |
ls_Emp_Data = . . . |
1 |
dw_employee.<span>ImportString</span>(ls_Emp_Data) |
This statement stores data in the string ls_Text
and imports it into the DataWindow dw_employee. The DataWindow
is a report of department 100 and start and end dates of personnel.
The string includes the department number and other information,
which is not imported. ImportString imports rows 2 through 10 and
columns 2 through 5 in the string to the DataWindow beginning in
column 2. The result is 9 rows added to the DataWindow with data
in columns 5 through 8:
1 |
string ls_text |
1 |
1 |
ls_text = "Dept~tLName~tFName~tStart" & <br> + "~tEnd~tAmount~tOutcome ~r~n" |
1 |
ls_text = ls_text + & |
1 |
"100~tJones~tMary~tApr88~tJul94~t40~tG~r~n" |
1 |
ls_text = ls_text + & |
1 |
"100~tMarsh~tMarsha~tApr89~tJan92~t35~tG~r~n" |
1 |
ls_text = ls_text + & |
1 |
"100~tJames~tHarry~tAug88~tMar93~t22~tM~r~n" |
1 |
... |
1 |
ls_text = ls_text + & |
1 |
"100~tWorth~tFrank~tSep87~tJun94~t55~tE~r~n" |
1 |
1 |
dw_employee.<span>ImportString</span>(ls_text, 2, 10, 2, 5, 5) |
This statement imports rows 1 to 200 of the data
in the XML string ls_emp, ignoring
any template mappings before column 5:
1 |
dw_employee.<span>ImportString</span>(ls_emp, 1, 200, 0, 0, 5) |