Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
| Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 11th, 2004, 03:01 AM
Friend of Wrox
 
Join Date: May 2004
Location: Ardabil, Ardabil, Iran.
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default How I Can N' Switch In My SQL Query In ADO.NET

How I Can Use N' Switch in My Sql Query That I am Encountered A Problem Such a Below Format In My Queries
strSql="select * from member_info where username=N'@username and password=N'@password";//
                    SqlDataAdapter objCommand=new SqlDataAdapter(strSql,objConnection);
                 objCommand.SelectCommand.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50));//.Value=username.Text;
                 objCommand.SelectCommand.Parameters["@username"].Value="ali";//username.Text;
                 objCommand.SelectCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarChar,50));
                 objCommand.SelectCommand.Parameters["@password"].Value="12"

Any One Help Me About This Problem .
Regards YoOrD
__________________
       YoOrD .
Beauty is not on the face
Beauty is on the heart
~~<<Ghibran Khalil>>~~
 
Old June 11th, 2004, 07:46 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You shouldn't need to use that when you are using a parameterized query.
 
Old June 11th, 2004, 09:37 AM
Friend of Wrox
 
Join Date: May 2004
Location: Ardabil, Ardabil, Iran.
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by planoie
 You shouldn't need to use that when you are using a parameterized query.
I have to use use this switch because without this option i cant or inserted or fetched data is not correct .
Regards YoOrD

 
Old June 11th, 2004, 10:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

The problem is the quotes around parameters in the query:

N'@username and password=N'@password

You shouldn't have those ' in the query; the ' will throw it off. Parameters don't use the ', otherwise it assumes the user name is '@username', Although with no ending quote that will throw an error also.

It should be:
username = @username and password = @password

Someone correct me if I'm wrong.

Brian
 
Old June 11th, 2004, 11:15 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Brian,

To my knowledge, you are correct. The question, how do we prefix the parameter with the N'? And is that necessary? I thought that using that prefix specifies the datatype for the string, so I would also think that by specifying the correct datatype for the parameter you are accomplishing the same thing. I'm not sure either way.
 
Old June 11th, 2004, 01:45 PM
Friend of Wrox
 
Join Date: May 2004
Location: Ardabil, Ardabil, Iran.
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by bmains
 Hello,

The problem is the quotes around parameters in the query:

N'@username and password=N'@password

You shouldn't have those ' in the query; the ' will throw it off. Parameters don't use the ', otherwise it assumes the user name is '@username', Although with no ending quote that will throw an error also.

It should be:
username = @username and password = @password

Someone correct me if I'm wrong.

Brian and Others That Notifies Me
thanx to brian.
but i examined it the only way that i can correctly insert data into a remote sql server database and when i ommite it the data was ureadable and substituted (or) each character replaced with a '?'
i must mentioned that i am using farsi or arabic collation to insert farsi data into a sql server database and the only solution that i found the i use the 'N Switch in my queries.
ant one have using this switch or this type experience.
i have had this problem ASP And Not In ASP.NET(ADO.NET) I dont know that i will encoutred such a problem in ASP.NET Or No But I think its a Query And It is Correct For All Type Of Query And I Use It Succefully In Query Analyzer And In The ASP And I Get The Proper Goal.
But I Must Check It In New Platform(.Net) And I Must Examine that is it work correct witnout using this switch with the Farsi Locals.
Thanx TO All:)
Any One To Help Me.

 
Old June 11th, 2004, 02:01 PM
Friend of Wrox
 
Join Date: May 2004
Location: Ardabil, Ardabil, Iran.
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by bmains
 Hello,

The problem is the quotes around parameters in the query:

N'@username and password=N'@password

You shouldn't have those ' in the query; the ' will throw it off. Parameters don't use the ', otherwise it assumes the user name is '@username', Although with no ending quote that will throw an error also.

It should be:
username = @username and password = @password

Someone correct me if I'm wrong.

Brian
Thanx To All I Must Notify Some Thing Here That I Have To Use Such Syntax For a Remote Sql Serverhttp://www.microsoft.com/middleeast/...port_characterThat Corrupts Data When I Am Going Inserting Some Thing Farsi And It is Unusable It Is Force Me To Use It.
Any One Can Lookup Above Link To Learn More .
Regards YoOrD.:)

 
Old June 13th, 2004, 02:39 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

if u use [u]VS.NET Visual mode </u>when u set ur CommandText to:
Code:
select * from member_info where username=@username and password=@password
It will create ur Paramaeters & U'll only need to set them.
but if u dont use [u]VS.NET Visual mode</u> u just set ur test to:
Code:
select * from member_info where username=@username and password=@password
Again & set ur Parameters urself.

HTH.


Always:),
Hovik Melkomian.




Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO.NET connectivity problem with SQL Server !!! virajp ADO.NET 2 December 5th, 2005 11:51 PM
SQL Server with ADO.NET dounme SQL Server 2000 4 February 8th, 2005 09:19 PM
ADO.Net slower than SQL Server Query Analyzer s5g5r ADO.NET 1 January 26th, 2005 09:49 PM
how can i link to sql-server with ado.net[B)] zjxgjp ADO.NET 1 December 25th, 2004 09:50 AM
MSDE and SQL CE (using VB.NET and ADO.NET) LEGS ADO.NET 0 July 12th, 2003 11:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.