NewRow() method is filling SQL fields with trailing spaces

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I know this is probably a stupid question but I can't find any threads anywhere regarding this

I have a SQL table that has largely char type columns and I use the following code to add a new row
Once added, all the fields in the new row are filled up to their limit with trailing spaces. So a 5 character field should read as "Test", it's actually being saved as "Test ". When I use an update procedure (for editing a row) it doesn't do this
What am I doing wrong

Any help would be greatly appreciated

DataRow oDr1 = oDs1.Tables["DIDH"].NewRow();
DataColumnCollection oDc1 = oDs1.Tables["DIDH"].Columns
int iTotCol = oDc1.Count

for (int i=1;i<iTotCol;i++

oDataRow = txtArray1.Text.Trim();


oDs1.Tables["DIDH"].Rows.Add(oDr1)
oOleDtAd.Update(oDs1,"DIDH")
oDs1.AcceptChanges()
 
LoC said:
I know this is probably a stupid question but I can't find any
threads anywhere regarding this.

I have a SQL table that has largely char type columns and I use the following code to add a new row.
Once added, all the fields in the new row are filled up to their
limit with trailing spaces. So a 5 character field should read as
"Test", it's actually being saved as "Test ". When I use an update
procedure (for editing a row) it doesn't do this.

What's the type of the column, exactly?
 
I have a SQL table that has largely char type columns

I'm 100% sure, but if your column in SQL uses a data type of char, then
that is a fixed length type. For example, if the column is defined as Char
with a length of 20, you will always use 20 characters of storage on SQL
server, regardless of the length of the data. If you change the data type
to Varchar, then it only stores the characters in the actual data and
doesn't pad the column out.
 
Back
Top