DataSet.Fill() When Column Value is Space

  • Thread starter Thread starter Mike Gage
  • Start date Start date
M

Mike Gage

I am trying to populate DataSets with results from SQL queries.
Usually, to that end, the DataSet.Fill method works fine. If however
the table includes a character field populated with a space, the
DataSet throws an exception. I assume that the restriction is because
of the DataSet's use of XML. I tried setting the XMLDataDocument's
PreserveWhiteSpace property, but to no avail.

The error message I receive is:
The DataSet Xml persistency does not support the value '0x20' as Char
value, please use Byte storage instead.
at System.Data.Common.CharStorage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object
value)Couldn't store < > in spec_handling Column. Expected type is
Char.


There must be a simple way to handle spaces in DataSets. Has anyone
found it?

Thanks.

-Mike Gage
 
I've never had problem with spaces in dataset.
Do you have generate the dataset from the dataadapter? Change the dataset
collum type to string or how suggested to byte.
 
Thanks for the reply.

I am running tests where I don't explicitly define the dataset, but
where it is defined based upon the query that is populating the dataset.
This almost always works just fine. The problem comes when there is a
CHAR(1) column populated with a space.

The applicable code where I populate the dataset is:

------------------------------------------------------public void
executeStatement( string statement )
{
checkConnection( statement );
try
{
IfxDataAdapter dataAdapter = new IfxDataAdapter( statement,
ifxConnection );
DataSet dataSet = new DataSet( "dataset" );
dataAdapter.Fill( dataSet );
resultsFileStream.Flush();
resultsFileStreamWriter.WriteLine( "\r\n\r\nResults from
executing statement: \"" + statement + "\"" );
resultsFileStreamWriter.Flush();
dataSet.WriteXml( resultsFileStream );
resultsFileStream.Flush();
}
catch( IfxException e )
{
Console.WriteLine( "Exception caught while attempting to
execute: \"" + statement + "\"" );
printIfxExceptionInfo( e );
}
catch( Exception e )
{
Console.WriteLine( "Exception caught while attempting to
execute: \"" + statement + "\"" );
Console.WriteLine( e.Message );
}
}
-------------------------------------------------------
 
Back
Top