|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
A parameter character similar to AccessI'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 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 -- Show quoteHope 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 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 > > > 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. -- Show quoteHope 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 >> >> >> 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 > >> > >> > >> > > > |
|||||||||||||||||||||||