Home All Groups Group Topic Archive Search About

A parameter character similar to Access

Author
9 Jul 2005 2:58 PM
Nick Zdunic
I'm using .NET to access the database.

Using MS Access I can write a query such as 'Select Password From Users
Where UserID = ?'

I can populate a parameter collection and associate it with the query and it
will return the result.

Is this possible under SQL Server.  If so what is the parameter character I
should be using?

Thanks,

Nick

Author
9 Jul 2005 3:57 PM
Dan Guzman
If you are using System.Data.OleDb, you can use a '?' in SQL Server queries
just like your Access example.  With System.Data.SqlClient, you can specify
parameter names in your command text:

SELECT Password FROM Users
WHERE UserID = @UserID

--
Hope this helps.

Dan Guzman
SQL Server MVP

Show quote
"Nick Zdunic" <NickZdu***@discussions.microsoft.com> wrote in message
news:FF2EA762-3C73-44B2-B88D-47982E724765@microsoft.com...
> I'm using .NET to access the database.
>
> Using MS Access I can write a query such as 'Select Password From Users
> Where UserID = ?'
>
> I can populate a parameter collection and associate it with the query and
> it
> will return the result.
>
> Is this possible under SQL Server.  If so what is the parameter character
> I
> should be using?
>
> Thanks,
>
> Nick
Author
9 Jul 2005 4:36 PM
Nick Zdunic
And do the parameter names have to be unique in SqlClient, or can I use the
same name - @1 for instance

e.g. SELECT Password FROM Users WHERE UserID = @1 AND Active=@1



Show quote
"Dan Guzman" wrote:

> If you are using System.Data.OleDb, you can use a '?' in SQL Server queries
> just like your Access example.  With System.Data.SqlClient, you can specify
> parameter names in your command text:
>
> SELECT Password FROM Users
> WHERE UserID = @UserID
>
> --
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
>
> "Nick Zdunic" <NickZdu***@discussions.microsoft.com> wrote in message
> news:FF2EA762-3C73-44B2-B88D-47982E724765@microsoft.com...
> > I'm using .NET to access the database.
> >
> > Using MS Access I can write a query such as 'Select Password From Users
> > Where UserID = ?'
> >
> > I can populate a parameter collection and associate it with the query and
> > it
> > will return the result.
> >
> > Is this possible under SQL Server.  If so what is the parameter character
> > I
> > should be using?
> >
> > Thanks,
> >
> > Nick
>
>
>
Author
9 Jul 2005 4:53 PM
Dan Guzman
Yes, parameter names need to be unique because the SqlClient API declares
Transact-SQL variables with these names.  IMHO, it's best to give parameters
meaningful names too.

--
Hope this helps.

Dan Guzman
SQL Server MVP

Show quote
"Nick Zdunic" <NickZdu***@discussions.microsoft.com> wrote in message
news:925D99B6-0C6A-4DE9-930B-70BC2EF610CB@microsoft.com...
> And do the parameter names have to be unique in SqlClient, or can I use
> the
> same name - @1 for instance
>
> e.g. SELECT Password FROM Users WHERE UserID = @1 AND Active=@1
>
>
>
> "Dan Guzman" wrote:
>
>> If you are using System.Data.OleDb, you can use a '?' in SQL Server
>> queries
>> just like your Access example.  With System.Data.SqlClient, you can
>> specify
>> parameter names in your command text:
>>
>> SELECT Password FROM Users
>> WHERE UserID = @UserID
>>
>> --
>> Hope this helps.
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "Nick Zdunic" <NickZdu***@discussions.microsoft.com> wrote in message
>> news:FF2EA762-3C73-44B2-B88D-47982E724765@microsoft.com...
>> > I'm using .NET to access the database.
>> >
>> > Using MS Access I can write a query such as 'Select Password From Users
>> > Where UserID = ?'
>> >
>> > I can populate a parameter collection and associate it with the query
>> > and
>> > it
>> > will return the result.
>> >
>> > Is this possible under SQL Server.  If so what is the parameter
>> > character
>> > I
>> > should be using?
>> >
>> > Thanks,
>> >
>> > Nick
>>
>>
>>
Author
9 Jul 2005 5:32 PM
Nick Zdunic
Agree about meaningful names - but in my current situation it doesn't matter
and it actually makes my application easier if they weren't unique.

Show quote
"Dan Guzman" wrote:

> Yes, parameter names need to be unique because the SqlClient API declares
> Transact-SQL variables with these names.  IMHO, it's best to give parameters
> meaningful names too.
>
> --
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
>
> "Nick Zdunic" <NickZdu***@discussions.microsoft.com> wrote in message
> news:925D99B6-0C6A-4DE9-930B-70BC2EF610CB@microsoft.com...
> > And do the parameter names have to be unique in SqlClient, or can I use
> > the
> > same name - @1 for instance
> >
> > e.g. SELECT Password FROM Users WHERE UserID = @1 AND Active=@1
> >
> >
> >
> > "Dan Guzman" wrote:
> >
> >> If you are using System.Data.OleDb, you can use a '?' in SQL Server
> >> queries
> >> just like your Access example.  With System.Data.SqlClient, you can
> >> specify
> >> parameter names in your command text:
> >>
> >> SELECT Password FROM Users
> >> WHERE UserID = @UserID
> >>
> >> --
> >> Hope this helps.
> >>
> >> Dan Guzman
> >> SQL Server MVP
> >>
> >> "Nick Zdunic" <NickZdu***@discussions.microsoft.com> wrote in message
> >> news:FF2EA762-3C73-44B2-B88D-47982E724765@microsoft.com...
> >> > I'm using .NET to access the database.
> >> >
> >> > Using MS Access I can write a query such as 'Select Password From Users
> >> > Where UserID = ?'
> >> >
> >> > I can populate a parameter collection and associate it with the query
> >> > and
> >> > it
> >> > will return the result.
> >> >
> >> > Is this possible under SQL Server.  If so what is the parameter
> >> > character
> >> > I
> >> > should be using?
> >> >
> >> > Thanks,
> >> >
> >> > Nick
> >>
> >>
> >>
>
>
>

AddThis Social Bookmark Button