Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert int to string inside SQL string?

Status
Not open for further replies.

777axa

Technical User
Jul 30, 2002
48
US

Inside SQL string I'm building a path to the image file named by EmployeeID #

***************************************
strSQL = "SELECT EmployeeID, " & _
"FirstName, LastName, " & _
"(FirstName + ' ' + LastName) As Name, " & _
"('Img\' + EmployeeID + '.jpg') As PhotoURL, " & _
"DateLastEval, DateActualEval, DateNextEval, DateLastMerit, DateActualMerit, DateNextMerit, NotesEval, NotesMerit " & _
"FROM Employees WHERE LastName LIKE '" & rblAlpha.SelectedItem.Text & "%'"
***************************************

SQL string is passed to GetDataSet function iside a Class

***************************************
Public Shared Function GetDataSet( _
ByVal SQLString As String, _
ByVal ConnectionString As String) As DataSet
Dim da As OleDbDataAdapter
Dim ds As DataSet
Try
' Create new DataAdapter
da = New OleDbDataAdapter( _
SQLString, ConnectionString)
' Fill DataSet from DataAdapter
ds = New DataSet()
da.Fill(ds)
Catch
Throw
End Try
Return ds
End Function
***************************************************
I need to convert EmployeeID to string to build a path but I'm not sure where and how.
Your help is very much appreciated.
 
Are you getting an error when you try and run this? The sql string that you have now looks like it should just work on its own, but if you want to make sure that the value definately is in a string format, just go

CStr(EmployeeID)

in your sql statement. The CStr will cast your EmployeeID variable as a string. There are other casts as well like CInt (for casting a string that is a number to an integer datatype), CDbl, CBool, etc.

But as is, I *think* that your sql statement should be ok on its own. It looks like you are using C#, so maybe it handles things differently than in vb.net?

hth

D'Arcy
 
I'm using VB.
The string as it is now gives an error:
"Syntax error converting the varchar value 'Img\' to a column of data type int."
So I'm sure that the reason for this error is this EmlpoyeeID int.
If I don't append it there is no error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top