|
-
Mar 30th, 2009, 07:33 AM
#1
Thread Starter
Junior Member
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
-
Mar 30th, 2009, 07:53 AM
#2
Addicted Member
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
-
Mar 30th, 2009, 10:21 AM
#3
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|