using parameters, yet single apostrophe dropping

  • Thread starter Thread starter SpaceMarine
  • Start date Start date
S

SpaceMarine

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
 
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
 
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)
____________________________________________________________________________________________
 
Dans :
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)
 
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
 
Back
Top