How do I keep trailing spaces from being trimmed?

R

rsine

I am developing a program that requires me to read a string of data from
a text field in a database. Data is parsed from the string based upon a
starting position/length. If a piece of data doesn't meet the required
field length, then spaces are added, thus my issue. It appears VB.net
is trimming any trailing spaces. What should be a 250 character data
string is only 243 (less 7 trailing spaces). Is there a way to get this
to stop? I manually checked the data in the database counting the number
of characters and 250 was the correct.

-Thanks
 
C

CJ Taylor

Is your data type in your database set to
VARCHAR or is it set to CHAR

VarChar will automaticlly trim spaces... char will pad..

-cJ
 
R

rsine

CJ,

It is an AS/400 database that I am connecting into via ODBC. I look at
the data in Access and everything is the right length. I am not sure if
there is something going on when I populate my dataset wherein it is
trimming trailing spaces when I do a .Fill or not. The following is the
code I am using:

Dim mOLEDBCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand(sSQL,
mRemoteConnection)

mOLEDBCommand.CommandTimeout = 60

'issue the SELECT command via SQLAdapter
Dim mOLEDBAdapter As OleDb.OleDbDataAdapter = New
OleDb.OleDbDataAdapter mOLEDBAdapter.SelectCommand = mOLEDBCommand

'establish connection to remote database
mRemoteConnection.Open()

mOLEDBAdapter.Fill(dsRemoteDataset, sRemoteEDIPF)

'close the connection
mRemoteConnection.Close()


Dim sData As String
sData =
dsRemoteDataset.Tables(sRemoteEDIPF).Rows(EDIIndexPos).Item("Data")

When I do a count of sData, the field has been trimmed.

I appreciate your help and welcome any further suggestions since this
has got me stumped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top