How do you pass a column name to the Where clause in a SQL Select Statement

Feb 25 2006 3:25 PM
I'm trying to pass the name of the column in a parameter as a string. No runtime errors but no rows are returned. There should be. If I replace @Column with the correct column name it works. Also setting a watch on @Column Value shows the correct column name. I would really apprecuate any help you can provide.
Thank you
See below:

Public Shared Function GetEmployeesAffected(ByVal Column As String, _ByVal Value As String) As Integer
Dim DBConnection As SqlConnection = EPICConnection()
Dim cmdSelect As New SqlCommand
cmdSelect.Connection = DBConnectioncmd
Select.CommandText = "Select COUNT(*) As RecordCount FROM Employees WHERE @Column = @Value"
Dim prmColumn As New SqlParameter("@Column", SqlDbType.VarChar)
cmdSelect.Parameters.Add(prmColumn)
cmdSelect.Parameters("@Column").Value = Column

Dim prmValue As New SqlParameter("@Value", SqlDbType.VarChar)
cmdSelect.Parameters.Add(prmValue)
cmdSelect.Parameters("@Value").Value = Value
DBConnection.Open()
Dim icount As Integer = cmdSelect.ExecuteScalar
DBConnection.Close()
Return icount

End Function