PC Review


Reply
Thread Tools Rate Thread

White Space Problem

 
 
Carlo Razzeto
Guest
Posts: n/a
 
      25th Aug 2003
First of all, sorry about cross posting but I wasn't sure which group this
question was more appropriate for...

I am having a problem with Microsoft SQL Server or SqlDataReader (most
likely the former) apparently appending white space to the end of database
results... The code I have looks like:

Dim ConnectionString = "Data Source=(local); User=sa; Password=Oper64Hammer;
Initial Catalog=my_work"
Dim Query = "SELECT UserName, PassWord, UserLevel FROM UserData WHERE
UserName = '" + user + "'"
Dim SQLConnection As New SqlConnection(ConnectionString)
SQLConnection.Open()
Dim Command As New SqlCommand(Query, SQLConnection)
Dim Reader As SqlDataReader = Command.ExecuteReader()

For some reason when I read from the password column of the result set I get
the password with with one black space appended to the end of the string.
This forced me to write store my password in a string then use the
string.trim method to remove the white space so I could accurately compare
the database result to the password entered by the user. What causes this
problem? And is there any way to correct it? I would hate to have to store
all my database results as strings so I can trim them when ever I need to
compare results to user input. Thanks for any help,

Carlo


 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      25th Aug 2003
What data type is the column set to in sql server? Is it a char or varchar?

"Carlo Razzeto" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> First of all, sorry about cross posting but I wasn't sure which group this
> question was more appropriate for...
>
> I am having a problem with Microsoft SQL Server or SqlDataReader (most
> likely the former) apparently appending white space to the end of database
> results... The code I have looks like:
>
> Dim ConnectionString = "Data Source=(local); User=sa;

Password=Oper64Hammer;
> Initial Catalog=my_work"
> Dim Query = "SELECT UserName, PassWord, UserLevel FROM UserData WHERE
> UserName = '" + user + "'"
> Dim SQLConnection As New SqlConnection(ConnectionString)
> SQLConnection.Open()
> Dim Command As New SqlCommand(Query, SQLConnection)
> Dim Reader As SqlDataReader = Command.ExecuteReader()
>
> For some reason when I read from the password column of the result set I

get
> the password with with one black space appended to the end of the string.
> This forced me to write store my password in a string then use the
> string.trim method to remove the white space so I could accurately compare
> the database result to the password entered by the user. What causes this
> problem? And is there any way to correct it? I would hate to have to store
> all my database results as strings so I can trim them when ever I need to
> compare results to user input. Thanks for any help,
>
> Carlo
>
>



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      25th Aug 2003
How are the columns defined in your UserData table?
Now that we know the SA password, all we need to know is ...
As a rule you should rarely (if ever) connect with the SA login. Keep the
password to yourself and create roles/permissions/logins to develop with and
use permissions to grant access.

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Carlo Razzeto" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> First of all, sorry about cross posting but I wasn't sure which group this
> question was more appropriate for...
>
> I am having a problem with Microsoft SQL Server or SqlDataReader (most
> likely the former) apparently appending white space to the end of database
> results... The code I have looks like:
>
> Dim ConnectionString = "Data Source=(local); User=sa;

Password=Oper64Hammer;
> Initial Catalog=my_work"
> Dim Query = "SELECT UserName, PassWord, UserLevel FROM UserData WHERE
> UserName = '" + user + "'"
> Dim SQLConnection As New SqlConnection(ConnectionString)
> SQLConnection.Open()
> Dim Command As New SqlCommand(Query, SQLConnection)
> Dim Reader As SqlDataReader = Command.ExecuteReader()
>
> For some reason when I read from the password column of the result set I

get
> the password with with one black space appended to the end of the string.
> This forced me to write store my password in a string then use the
> string.trim method to remove the white space so I could accurately compare
> the database result to the password entered by the user. What causes this
> problem? And is there any way to correct it? I would hate to have to store
> all my database results as strings so I can trim them when ever I need to
> compare results to user input. Thanks for any help,
>
> Carlo
>
>



 
Reply With Quote
 
Carlo Razzeto
Guest
Posts: n/a
 
      25th Aug 2003
Thanks for the advice... This is actually not an internet accessable site
right now, it's behind my broadband routers firewall... I would be a little
more careful if this was going to be a "real" web site on the internet but
since I'm just getting familiar with .Net (in this case VB of course) I was
just being... well... lazy...

Carlo

"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> How are the columns defined in your UserData table?
> Now that we know the SA password, all we need to know is ...
> As a rule you should rarely (if ever) connect with the SA login. Keep the
> password to yourself and create roles/permissions/logins to develop with

and
> use permissions to grant access.
>
> --
> ____________________________________
> Bill Vaughn
> MVP, hRD
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no

rights.
> __________________________________
>
> "Carlo Razzeto" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > First of all, sorry about cross posting but I wasn't sure which group

this
> > question was more appropriate for...
> >
> > I am having a problem with Microsoft SQL Server or SqlDataReader (most
> > likely the former) apparently appending white space to the end of

database
> > results... The code I have looks like:
> >
> > Dim ConnectionString = "Data Source=(local); User=sa;

> Password=Oper64Hammer;
> > Initial Catalog=my_work"
> > Dim Query = "SELECT UserName, PassWord, UserLevel FROM UserData WHERE
> > UserName = '" + user + "'"
> > Dim SQLConnection As New SqlConnection(ConnectionString)
> > SQLConnection.Open()
> > Dim Command As New SqlCommand(Query, SQLConnection)
> > Dim Reader As SqlDataReader = Command.ExecuteReader()
> >
> > For some reason when I read from the password column of the result set I

> get
> > the password with with one black space appended to the end of the

string.
> > This forced me to write store my password in a string then use the
> > string.trim method to remove the white space so I could accurately

compare
> > the database result to the password entered by the user. What causes

this
> > problem? And is there any way to correct it? I would hate to have to

store
> > all my database results as strings so I can trim them when ever I need

to
> > compare results to user input. Thanks for any help,
> >
> > Carlo
> >
> >

>
>



 
Reply With Quote
 
Marina
Guest
Posts: n/a
 
      25th Aug 2003
When you define a columns as char(15), that means there will always be 15
characters in that field. If you put anything smaller in, it will be padded
with spaces such so the field is always 15 in length. So if your string has
12 character, there will be 3 spaces afterwards.

If you do not want this behavior, use a varchar(15) type. This holds up to
15 characters, but does not pad with spaces.

"Carlo Razzeto" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Table is setup as follows
> UserData
> UserName char(15)
> Password char(15)
> UserLevel tinyint
>
> Carlo
>
> "Marina" <(E-Mail Removed)> wrote in message
> news:ei%(E-Mail Removed)...
> > What data type is the column set to in sql server? Is it a char or

> varchar?
> >
> > "Carlo Razzeto" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > First of all, sorry about cross posting but I wasn't sure which group

> this
> > > question was more appropriate for...
> > >
> > > I am having a problem with Microsoft SQL Server or SqlDataReader (most
> > > likely the former) apparently appending white space to the end of

> database
> > > results... The code I have looks like:
> > >
> > > Dim ConnectionString = "Data Source=(local); User=sa;

> > Password=Oper64Hammer;
> > > Initial Catalog=my_work"
> > > Dim Query = "SELECT UserName, PassWord, UserLevel FROM UserData WHERE
> > > UserName = '" + user + "'"
> > > Dim SQLConnection As New SqlConnection(ConnectionString)
> > > SQLConnection.Open()
> > > Dim Command As New SqlCommand(Query, SQLConnection)
> > > Dim Reader As SqlDataReader = Command.ExecuteReader()
> > >
> > > For some reason when I read from the password column of the result set

I
> > get
> > > the password with with one black space appended to the end of the

> string.
> > > This forced me to write store my password in a string then use the
> > > string.trim method to remove the white space so I could accurately

> compare
> > > the database result to the password entered by the user. What causes

> this
> > > problem? And is there any way to correct it? I would hate to have to

> store
> > > all my database results as strings so I can trim them when ever I need

> to
> > > compare results to user input. Thanks for any help,
> > >
> > > Carlo
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      25th Aug 2003
Marina is right. We rarely use Char anymore for anything except those fields
where we know the length will ALWAYS be a fixed number of characters. This
is handy for part numbers or somesuch but anytime you're working with a
field that varies in length, use a VarChar. In the "olden days", we often
looked for small ways to help reduce the size of the DB and using CHAR made
more sense back then. Nowadays it's more trouble than it's worth to use
CHAR.

hth

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Marina" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> When you define a columns as char(15), that means there will always be 15
> characters in that field. If you put anything smaller in, it will be

padded
> with spaces such so the field is always 15 in length. So if your string

has
> 12 character, there will be 3 spaces afterwards.
>
> If you do not want this behavior, use a varchar(15) type. This holds up

to
> 15 characters, but does not pad with spaces.
>
> "Carlo Razzeto" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Table is setup as follows
> > UserData
> > UserName char(15)
> > Password char(15)
> > UserLevel tinyint
> >
> > Carlo
> >
> > "Marina" <(E-Mail Removed)> wrote in message
> > news:ei%(E-Mail Removed)...
> > > What data type is the column set to in sql server? Is it a char or

> > varchar?
> > >
> > > "Carlo Razzeto" <(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > > > First of all, sorry about cross posting but I wasn't sure which

group
> > this
> > > > question was more appropriate for...
> > > >
> > > > I am having a problem with Microsoft SQL Server or SqlDataReader

(most
> > > > likely the former) apparently appending white space to the end of

> > database
> > > > results... The code I have looks like:
> > > >
> > > > Dim ConnectionString = "Data Source=(local); User=sa;
> > > Password=Oper64Hammer;
> > > > Initial Catalog=my_work"
> > > > Dim Query = "SELECT UserName, PassWord, UserLevel FROM UserData

WHERE
> > > > UserName = '" + user + "'"
> > > > Dim SQLConnection As New SqlConnection(ConnectionString)
> > > > SQLConnection.Open()
> > > > Dim Command As New SqlCommand(Query, SQLConnection)
> > > > Dim Reader As SqlDataReader = Command.ExecuteReader()
> > > >
> > > > For some reason when I read from the password column of the result

set
> I
> > > get
> > > > the password with with one black space appended to the end of the

> > string.
> > > > This forced me to write store my password in a string then use the
> > > > string.trim method to remove the white space so I could accurately

> > compare
> > > > the database result to the password entered by the user. What causes

> > this
> > > > problem? And is there any way to correct it? I would hate to have to

> > store
> > > > all my database results as strings so I can trim them when ever I

need
> > to
> > > > compare results to user input. Thanks for any help,
> > > >
> > > > Carlo
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Carlo Razzeto
Guest
Posts: n/a
 
      26th Aug 2003
Thanks guys, that really helped!

Carlo

"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Marina is right. We rarely use Char anymore for anything except those

fields
> where we know the length will ALWAYS be a fixed number of characters. This
> is handy for part numbers or somesuch but anytime you're working with a
> field that varies in length, use a VarChar. In the "olden days", we often
> looked for small ways to help reduce the size of the DB and using CHAR

made
> more sense back then. Nowadays it's more trouble than it's worth to use
> CHAR.
>
> hth
>
> --
> ____________________________________
> Bill Vaughn
> MVP, hRD
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no

rights.
> __________________________________



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
table problem; plz help me remove this white space! JoeDontKnow Microsoft Frontpage 6 17th Apr 2008 03:01 PM
White space! Malcolm Walker Microsoft Frontpage 20 9th Nov 2007 08:03 PM
Add/remove programmes white space problem =?Utf-8?B?VHJldm9y?= Windows XP General 4 5th Feb 2006 04:03 PM
Where are the "show white space" and "hide white space" buttons? =?Utf-8?B?Um9iaW4gSw==?= Microsoft Word Document Management 2 23rd Jun 2005 12:10 AM
Problem with white space on page Amar Microsoft ASP .NET 1 16th Jan 2004 04:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 PM.