extra characters on string

G

Guest

Hi,

I am retrieving data from a binary field from a sql table and I am having a
problem with extra characters being tacked onto the end. The thePass
variable has some unknown spaces after it but I can't seem to trim them. Any
help would be appreciated.

Thanks

Here is the sql statement I am using

SELECT CAST(password AS VARCHAR(50)) AS thePass FROM " + Session["dbOwner"]
+ "tblpassword WHERE USERNAME = '" + userName + "'"
 
A

Alberto Poblacion

bbdobuddy said:
I am retrieving data from a binary field from a sql table and I am having
a
problem with extra characters being tacked onto the end. The thePass
variable has some unknown spaces after it but I can't seem to trim them.
Any
help would be appreciated.

Here is the sql statement I am using

SELECT CAST(password AS VARCHAR(50)) AS thePass FROM " +
Session["dbOwner"]
+ "tblpassword WHERE USERNAME = '" + userName + "'"

What is the original type of the column "password"? Since you are casting
it to varchar, I assume that it was not originally a varchar. Maybe the type
of conversion that is taking place can give us a hint as to why additional
characters are appearing.

On a different note, be aware that this statement suffers a risk of
being subject to a sql injection. If the user, when entering the userName,
typed (for example) something like "';drop table tblpassword--", you would
be in trouble.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

bbdobuddy said:
Hi,

I am retrieving data from a binary field from a sql table and I am having
a
problem with extra characters being tacked onto the end. The thePass
variable has some unknown spaces after it but I can't seem to trim them.
Any
help would be appreciated.

Why are you casting it as varchar?
What does the original column hold? , In what format?
Thanks

Here is the sql statement I am using

SELECT CAST(password AS VARCHAR(50)) AS thePass FROM " +
Session["dbOwner"]
+ "tblpassword WHERE USERNAME = '" + userName + "'"
 

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