Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
0
Answer
How do you pass a column name to the Where clause in a SQL Select Statement
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Frank Donnelly
18y
1.4k
1
Reply
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
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
checkbox column problem....
Guidance