Results 1 to 13 of 13

Thread: [RESOLVED] ExecuteScalar tricking me.

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Resolved [RESOLVED] ExecuteScalar tricking me.

    I want to loop through my table and extract a UserName that corresponds with the UserName typed in a text box using the execute scarlar method.

    If it's there then i call a message and exit the sub, if its not there then i add the User.

    VB Code:
    1. Public Shared Function LookUp( ByVal strSQL As String) As String
    2.         Dim strValue As String = ""
    3.         Dim myConn As OleDbConnection = New OleDbConnection(strAccessConn)
    4.         Dim myCommand As New OleDbCommand(strSQL, myConn)
    5.         Try
    6.             myConn.Open()
    7.             strValue = CStr(myCommand.ExecuteScalar()) 'Option strict is on
    8.             myConn.Close()
    9.         Catch ex As Exception
    10.             MsgBox("Error:" & ex.Message)
    11.         End Try
    12.         Return strValue
    13.     End Function

    Here is my SQL
    VB Code:
    1. Dim  strUserName as string="SELECT UserName FROM Users WHERE(UserName='" & Me.tbUserName.text.Trim() & "')"

    My Execute scalar returns a string but i cant get the string when i call it like this. It Returns an empty messagebox

    VB Code:
    1. MessageBox.Show(LookUp(strUserName).toUpper)
    Last edited by maps; Jun 23rd, 2006 at 03:56 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width