TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Frank Donnelly
NA
1
0
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
Reply
Answers (
0
)
Setting a Parent GroupBox visiblity from a UserControl class
Guidance