Results 1 to 3 of 3

Thread: Pull 'Price' From 'Product' Table and Put Into A Label

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    24

    Smile Pull 'Price' From 'Product' Table and Put Into A Label

    Hey, i've had a quick search but couldnt find anything.

    Anyway, i have a list of products in a product table. Primary key 'id', and 'Price' is a float

    (all variables defined at the top - cut main code out)
    Code:
    objConnect = New OleDbConnection
    objConnect.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=|DataDirectory|\Ecommerce.accdb;"
    objCommand = New OleDbCommand
    objCommand.Connection = objConnect
    
            objConnect.Open()
            objCommand.CommandType = Data.CommandType.Text
    
            objCommand.CommandText = "SELECT Price from Product WHERE ProductID='1'"
    
                TextBox1.Text = objCommand.CommandText
                'TextBox2.Text = ... 
    
    
            objCommand.Parameters.Clear()
            objCommand.Connection.Close()
    I basically want to pull the PRICE from each product ID in the table and assign them to 6 different labels on my form (i have 6 products in the database 1-6) the code above is what i have atm (i was just trying to pull 1 price atm but it just says "SELECT PRICE... etc", in the textbox atm)

    Help apprechiated

  2. #2
    Addicted Member
    Join Date
    Dec 2008
    Posts
    185

    Re: Pull 'Price' From 'Product' Table and Put Into A Label

    replace
    Code:
    TextBox1.Text = objCommand.CommandText
    with
    Code:
    TextBox1.Text = objCommand.ExecuteScalar.ToString
    That should do it

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    24

    Re: Pull 'Price' From 'Product' Table and Put Into A Label

    so simple. thanks!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width