January 6th, 2013, 07:03 AM
Parameterized query to choose the column to select data from
I am trying to make a code that will let me display only entries of a database that are greater than the value entered in a textbox. I have a dropdown list that contains the columns of the database, it should only display the stats of the column that is selected from the dropdown list.
So for example if i have columns: A, B and C, and row 1 has 10, 15 and 20. Row 2 has 12, 17 and 22. And row 3 has 14, 19 and 24. And i select column B from the dropdown and put 16 in the textbox then it should only show 17 and 19 since those are in column B and are greater than 16. But right now when i try it it is displaying everything in the database.
This is the code i am using for it:
So can someone explain how i can use a parameterized query to select which column to get the data from?
sqlString = "SELECT * FROM table WHERE @column > @value"
dbCommand = New MySqlCommand(sqlString, dbConnection)
dbReader = dbCommand.ExecuteReader()
repeater.DataSource = dbReader
Catch ex As Exception