locked
asp.net VB web page SQL not working RRS feed

  • Question

  • User1535393768 posted

    I am getting a syntax error from my FROM SQL command in Visual Web Developer 2010.  I am using the HttpContext.Current.User.Identity.Name to get the user login, checking it against an Accesss 2007 database (.mdb).  I can change that SQL statement and everything will work fine if I sly away from using the HttpContext.Current.User.Identity.Name but I want to use this.  Any help?

        Protected Sub Button4_Click(sender As Object, e As System.EventArgs) Handles Button4.Click
            Dim ConnString As String = GetConnString()
            Dim currentUserID As String = HttpContext.Current.User.Identity.Name
            Dim SqlString As String = "Select FirstName From User Where SubmitedBy = ?"
    
            Using conn As New OleDbConnection(ConnString)
                Using cmd As New OleDbCommand(SqlString, conn)
                    cmd.CommandType = Data.CommandType.Text
                    cmd.Parameters.AddWithValue("SubmitedBy", currentUserID)
    
                    conn.Open()
                    Using reader As OleDbDataReader = cmd.ExecuteReader()
                        While reader.Read()
                            TestLabel.Text = reader("FirstName").ToString()
                        End While
                    End Using
                End Using
            End Using
        End Sub


    Wednesday, May 9, 2012 4:00 PM

Answers

  • User-2010311731 posted

    Are you getting an error message when you use this?

    If not, check the value that HttpContext.Current.User.Identity.Name is returning.  Many times, it is pre-pending your domain to the username like "MYDOMAIN\myusername".  You may need to parse this out in order to compare with a value in your database by using HttpContext.Current.User.Identity.Name.SubString(9)

     

    Matt

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 9, 2012 5:17 PM

All replies

  • User-2010311731 posted

    Are you getting an error message when you use this?

    If not, check the value that HttpContext.Current.User.Identity.Name is returning.  Many times, it is pre-pending your domain to the username like "MYDOMAIN\myusername".  You may need to parse this out in order to compare with a value in your database by using HttpContext.Current.User.Identity.Name.SubString(9)

     

    Matt

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 9, 2012 5:17 PM
  • User1535393768 posted

    AZMatt, you hit it on the head.  Once I parsed out the domain and the "\" everything was fine.

    Thank you,

    LMB

    Thursday, May 10, 2012 11:01 AM