unicode / ANSI question with parameters

G

Guest

hi,

I have a question regarding the following senario:

I have a query (not a stored procedure):

"SELECT memberID, email from tbl_User Where login = @login"

And then I use the addWithValue method new to 2.0 to add it like the
following:

cmd.parameters.addWithValue("@login", login)

Assuming the column [login] is of type nVarchar(50), how can I be sure that
when I addWithValue, the data is passed as nvarchar? I am a bit confused
because in the query I did not Declare @login nvarchar(50) as I normally
would with stored procedure. Or should I construct the query as

"SELECT memberID, email from tbl_User Where login = N'" + login + "' "

instead?

What about the senario when the column [login] is of type varchar(50)?
Assuming that the response and request encoding in my ASP.NET 2.0 application
are both "UTF-8", will I be able to work with non-unicode column with
AddWithValue without specifying the parameter data type? Or will ADO do the
job for me by first discovering the data type?
 
K

Kevin Yu [MSFT]

Hi,

AddWithValue method only set the name and the value of the parameter and
add it to the collection. This method returns a SqlParameter object. In
this case, you have to set the parameter's SqlDbType property to
SqlDbType.NVarChar and set the parameter Size property to 50.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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