hello,

i have some simple code that updates my db w/ a user-input string. as
always, i use a Command object w/ Parameters, and pass my text in as
such. like so:

//conn & command
SqlConnection conn = new SqlConnection(myConnStr);
SqlCommand command = new SqlCommand("UpdateFoo", conn);
command.CommandType = CommandType.StoredProcedure;

//params
command.Parameters.Add("@height", SqlDbType.VarChar, 10).Value =
height;

...the height variable is in the format, "6'7". it was my
understanding that since its a parameter, the db would be cool w/ the
single apostrophe. yet, when i review my table's rows, only "6" is
inserted.

any idea what's up?


thanks,
sm

RE: using parameters, yet single apostrophe dropping by KerryMoorman

KerryMoorman
Tue Jul 22 16:21:01 CDT 2008

sm,

I don't have any problem writing that value, "6'7", to a SQL Server table.

The data type of the column in my table is nvarchar(50).

I am using adhoc sql, not a stored procedure and I add the parameter using
the AddWithValue method instead of the Add method that you are using.

I wouldn't think any of these details would make a difference however.

Kerry Moorman


"SpaceMarine" wrote:

> hello,
>
> i have some simple code that updates my db w/ a user-input string. as
> always, i use a Command object w/ Parameters, and pass my text in as
> such. like so:
>
> //conn & command
> SqlConnection conn = new SqlConnection(myConnStr);
> SqlCommand command = new SqlCommand("UpdateFoo", conn);
> command.CommandType = CommandType.StoredProcedure;
>
> //params
> command.Parameters.Add("@height", SqlDbType.VarChar, 10).Value =
> height;
>
> ....the height variable is in the format, "6'7". it was my
> understanding that since its a parameter, the db would be cool w/ the
> single apostrophe. yet, when i review my table's rows, only "6" is
> inserted.
>
> any idea what's up?
>
>
> thanks,
> sm
>

Re: using parameters, yet single apostrophe dropping by William

William
Tue Jul 22 17:02:42 CDT 2008

Well, there might be another issue or two. The column is ASCII not Unicode.
If you're trying to save a "smart" apostrophe (as Word generates) it might
be there but be unprintable in some applications or out of the range of
valid characters.

Otherwise using a Parameter to pass the "O'Malley" string to the server
should work.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________



"SpaceMarine" <spacemarine@mailinator.com> wrote in message
news:8dbe5631-d507-409a-b8c8-b5e3ed53395b@34g2000hsh.googlegroups.com...
> hello,
>
> i have some simple code that updates my db w/ a user-input string. as
> always, i use a Command object w/ Parameters, and pass my text in as
> such. like so:
>
> //conn & command
> SqlConnection conn = new SqlConnection(myConnStr);
> SqlCommand command = new SqlCommand("UpdateFoo", conn);
> command.CommandType = CommandType.StoredProcedure;
>
> //params
> command.Parameters.Add("@height", SqlDbType.VarChar, 10).Value =
> height;
>
> ...the height variable is in the format, "6'7". it was my
> understanding that since its a parameter, the db would be cool w/ the
> single apostrophe. yet, when i review my table's rows, only "6" is
> inserted.
>
> any idea what's up?
>
>
> thanks,
> sm


Re: using parameters, yet single apostrophe dropping by Fred

Fred
Wed Jul 23 04:31:20 CDT 2008

Dans :
news:8dbe5631-d507-409a-b8c8-b5e3ed53395b@34g2000hsh.googlegroups.com,
SpaceMarine écrivait :
> hello,

Hello,

> ...the height variable is in the format, "6'7". it was my
> understanding that since its a parameter, the db would be cool w/ the
> single apostrophe. yet, when i review my table's rows, only "6" is
> inserted.
>
> any idea what's up?

Another idea.
What about if you try with 67 ?
If the sql procedure parameter is declared without the size, it seems to
me that it is only one char.

@height AS varchar <- only one char
@height AS varchar(10)


--
Fred
foleide@free.fr


Re: using parameters, yet single apostrophe dropping by SpaceMarine

SpaceMarine
Thu Jul 31 10:38:15 CDT 2008

On Jul 23, 4:31=A0am, "Fred" <fole...@free.fr.invalid> wrote:
> Another idea.
> What about if you try with 67 ?
> If the sql procedure parameter is declared without the size, it seems to
> me that it is only one char.
>
> @height AS varchar <- only one char
> @height AS varchar(10)


you were correct, the parameter size in the proc was not set
properly.


thanks!
sm