Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is this a valid SQL Statement??

 

"SELECT Last INTO txtLast.Text.ToString FROM tmUserInfo WHERE UserID = 'tehon3299'"

 

UserID is in table tmUserInfo and Last is in the table also. If I put that query in the SQL Query Analyzer with out the INTO statement it works fine. I'm just not sure about that INTO statement. It must be wrong, because it is not working.

 

Thanks

Thanks,

Tehon

  • Moderators
Posted

It looks like you want txtLast to display the value of Last for user 'tehon3299', am I correct?

 

try this...

   Private Function GetTableValue(ByVal sUser As String) As String
       Dim drSqlReader As SqlDataReader
       Dim SqlCMD As SqlCommand
       Dim SqlCN As New SqlConnection(Conn)'Conn is your connection string
       Dim strSql As String, sTemp As String
       Try
           If SqlCN.State = ConnectionState.Closed Then SqlCN.Open()
           strSql = "SELECT Last FROM tmUserInfo WHERE UserID = '" & sUser & "'"
           SqlCMD = New SqlCommand(strSql, SqlCN)
           drSqlReader = SqlCMD.ExecuteReader()

           While drSqlReader.Read
               sTemp = CType(drSqlReader.Item("UserID"), String)
           End While
       Catch
           sTemp = ""
       Finally
           If Not SqlCN.State = ConnectionState.Closed Then SqlCN.Close()
           If Not drSqlReader.IsClosed Then drSqlReader.Close()
           If Not SqlCMD Is Nothing Then SqlCMD.Dispose()
       End Try
       Return sTemp
   End Function

'call the function like this...
txtLast.Text = GetTableValue ("tehon3299")

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...