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
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
If this helps, please mark as Answer.
Marked as answer by Lord Moldybutt on May 10, 2012 03:01 PM
Lord Moldybu...
Member
4 Points
17 Posts
asp.net VB web page SQL not working
May 09, 2012 08:00 PM|LINK
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 SubAZMatt
Star
10648 Points
1896 Posts
Re: asp.net VB web page SQL not working
May 09, 2012 09:17 PM|LINK
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
Lord Moldybu...
Member
4 Points
17 Posts
Re: asp.net VB web page SQL not working
May 10, 2012 03:01 PM|LINK
AZMatt, you hit it on the head. Once I parsed out the domain and the "\" everything was fine.
Thank you,
LMB