Is this valid??

tehon3299

Well-known member
Joined
Jan 6, 2003
Messages
155
Location
Liverpool, NY
Is this a valid SQL Statement??

Code:
"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. Im just not sure about that INTO statement. It must be wrong, because it is not working.

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

try this...
Code:
    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")
 
Back
Top