
January 6th, 2013, 07:03 AM
|
|
Registered User
|
|
Join Date: Mar 2012
Posts: 15
Time spent in forums: 7 h 59 m 23 sec
Reputation Power: 0
|
|
|
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:
Code:
Try
dbConnection.Open()
sqlString = "SELECT * FROM table WHERE @column > @value"
dbCommand = New MySqlCommand(sqlString, dbConnection)
dbCommand.Parameters.AddWithValue("@column", dropdownlist.SelectedValue)
dbCommand.Parameters.AddWithValue("@value", textbox.Text)
dbReader = dbCommand.ExecuteReader()
repeater.DataSource = dbReader
repeater.DataBind()
dbReader.Close()
Catch ex As Exception
Response.Write(ex)
Finally
dbConnection.Close()
End Try
So can someone explain how i can use a parameterized query to select which column to get the data from?
|