MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 6th, 2013, 07:03 AM
robgw3 robgw3 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 15 robgw3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Parameterized query to choose the column to select data from

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap