Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get data based on NT userID

Status
Not open for further replies.
Apr 3, 2005
32
US
I have a select statement that filter data based on NT userID. But how can I do that?

This is what I tried, but it is generating error.

"SELECT distinct JOB_TITLE_CODE from ALL_PEOPLE where PERSON_INITIALS = Environ('username')", SqlConnection1)

Any suggestion??
Thanks in advance.
 
SELECT distinct JOB_TITLE_CODE from ALL_PEOPLE where PERSON_INITIALS = Environment.UserName
 
I tried the following code, but it doesn't give me any record back.

Dim strUser As String
strUser = Environment.UserName
Dim cmdAcctUnit As New SqlCommand("Select distinct JOB_TITLE_CODE from ALL_PEOPLE where PERSON_INITIALS = '@strUser'", SqlConnection1)
Dim drClass As SqlDataReader

I'm new at this, so I'm wondering what am I doing wrong?
Thanks,
-Diana
 
Dim cmdAcctUnit As New SqlCommand("Select distinct JOB_TITLE_CODE from ALL_PEOPLE where PERSON_INITIALS = " & strUser & "", SqlConnection1)


That should do the trick. You were trying to use SQL Server syntax for variables when you should be using the .net syntax.

Keep us posted...
 
This is what I have as my total for Page_Load

Dim strUser As String
strUser = Environment.UserName
Dim cmdAcctUnit As New SqlCommand("Select distinct JOB_TITLE_CODE from ALL_PEOPLE where PERSON_INITIALS = " & strUser & "", SqlConnection1)
Dim drClass As SqlDataReader
SqlConnection1.Open()
drClass = cmdAcctUnit.ExecuteReader()
lstAcctUnit.DataSource = drClass
lstAcctUnit.DataTextField = "JOB_TITLE_CODE"
lstAcctUnit.DataBind()
drClass.Close()
SqlConnection1.Close()

However, when I run it, it gives me the following error msg.
And 'a1a' is the NT userID.


Invalid column name 'a1a'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'a1a'.

Source Error:


Line 129: Dim drClass As SqlDataReader
Line 130: SqlConnection1.Open()
Line 131: drClass = cmdAcctUnit.ExecuteReader()
Line 132: lstAcctUnit.DataSource = drClass
Line 133: lstAcctUnit.DataTextField = "JOB_TITLE_CODE"

 
Never mind....I got it figure out...I just need a single quote around the variable.
Thank you for the help!!!!!!!! I really appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top