Monday, March 26, 2012

Passing LoginName into SQL query

How do I pass the user's LoginName into the WHERE clause of a SQL query?

I created the following query, but I don't know how to get the user's LoginName and pass its value into Param1. Nothing I try works.

SELECT property.propertyid, property.shortdesc, property.shortdesclink, property.text, property.UserID, [User].UserID AS Expr1, [User].Name FROM property INNER JOIN [User] ON property.UserID = [User].UserID WHERE ([User].Name = @.Param1)

hi, when ever u connecting with sqlserver then

following code will help u in passing parameter

Dim sqlcmd as new sqlcommand

sqlcmd.commandtext =" your query"

Sqlcmd.commandtype= commandtype.text

sqlcmd.parameters.add("@.param1", "loginName")

just add the above lines i hope it will help u.

Smile [:)]

No comments:

Post a Comment