lapucca
asked on
Why I get all these extra blanks after I used Trim()?
The LastName in the database would get a lot of extra trailing blanks. Why? Attached file is the sql sp called from the code snipt.
SqlDataSource sdsDoctors = new SqlDataSource();
sdsDoctors.ConnectionString = WebConfigurationManager.ConnectionStrings["AdaptSurveyConnectionString"].ToString();
sdsDoctors.InsertCommand = "usp_InsertNewDoctor";
sdsDoctors.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
sdsDoctors.InsertParameters.Add("FirstName", txtFirstName.Text.Trim());
sdsDoctors.InsertParameters.Add("LastName", txtLastName.Text.Trim());
int success = sdsDoctors.Insert();
usp-InsertNewDoctor.sql
check that the type starts with n (nchar,nvarchar,ntext)
And if your column types are nchar/varchar/ntext then split out the trim statement and see if its working e.g.
String TempFirstName = txtFirstName.Text.Trim();
sdsDoctors.InsertParameter s.Add("Fir stName", TempFirstName);
Slap a breakpoint on the line and inspect TempFirstName, and if it hasn't worked look at the char code - it may not be a regular space.
But my guess will be the table definition as Eyal says...
String TempFirstName = txtFirstName.Text.Trim();
sdsDoctors.InsertParameter
Slap a breakpoint on the line and inspect TempFirstName, and if it hasn't worked look at the char code - it may not be a regular space.
But my guess will be the table definition as Eyal says...
ASKER
Here is my table definition. I can't remember why I used nchar type. Does this type pad blanks at the end?
CREATE TABLE [dbo].[Doctors](
[DoctorId] [int] IDENTITY(1,1) NOT NULL,
[LastName] [nchar](30) NOT NULL,
[FirstName] [nchar](30) NULL,
[FullName] [nchar](60) NULL,
CONSTRAINT [PK_Doctors] PRIMARY KEY CLUSTERED
(
[DoctorId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
in the table all seems ok
post the definition of usp_InsertNewDoctor
post the definition of usp_InsertNewDoctor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
usp_InsertNewDoctor is the attached file when I open this question.
Of course Slimfinger has the right of it...
ASKER
I did check the LastName text in debug and it doesn't have any extra space.
string lName = txtLastName.Text.Trim();
sdsDoctors.InsertParameter s.Add("Las tName", lName);
string lName = txtLastName.Text.Trim();
sdsDoctors.InsertParameter
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.