Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2005, 11:32 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default Databinding to a label

Hey all,
I'm trying to databind to a label, but I keep getting compiler error, my code is below, Can someone please help.
Code:
Label38.Text = "Price"
Label38.Datasource = serverprice(Label2.text)
Label38.DataBind()

THE FUNCTION serverprice is as follows

Dim queryString As String = "SELECT [System].[Price] FROM [System] WHERE ([System].[Server_ID] = @Server_ID)"
        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim dbParam_server_ID As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
        dbParam_server_ID.ParameterName = "@Server_ID"
        dbParam_server_ID.Value = server_ID
        dbParam_server_ID.DbType = System.Data.DbType.String
        dbCommand.Parameters.Add(dbParam_server_ID)

        Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
        dataAdapter.SelectCommand = dbCommand
        Dim dataSet As System.Data.DataSet = New System.Data.DataSet
        dataAdapter.Fill(dataSet)
What I'm trying to do is get the price for the server from the DB and display it in the label
As always all help is appreciated

 
Old August 1st, 2005, 01:20 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

A Label doesn't have a DataSource. Instead, you can bind its Text property in code behind. Something like this will work:

Label38.Text = serverprice(Label2.text)

Where serverprice returns a *string*, like this:

Return myDataSet.Tables(0).Rows(0)("YourColumn").ToString ()

This code returns the column called YourColumn from the first row of the first table in the dataset.

If you only need a single string returned from serverprice, then you could use the quicker DataReader or a stored procedure with out put parameters.

HtH,

Imar

P.S. Nice and descriptive variable names.... ;)

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Tarantula by This Mortal Coil (Track 6 from the album: Filigree and Shadow) What's This?
 
Old August 2nd, 2005, 03:09 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar,
I'll give that a try I'm not sure how to code it, but how would I implement the;

Return myDataSet.Tables(0).Rows(0)("Price").ToString()

into my code??

Label38 = Return myDataSet.Tables(0).Rows(0)("Price").ToString()??? ?

If you could please assist me, many thanks.


D
 
Old August 14th, 2005, 04:19 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Oops, I missed your reply in this thread. Is this still an issue for you??

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
DataBinding with Radiobuttons vgsgowrisankar C# 2005 0 May 8th, 2008 05:15 AM
databinding for datagrid? drachx General .NET 5 October 28th, 2004 03:21 AM
format and databinding marclena VS.NET 2002/2003 1 February 11th, 2004 09:11 PM
Dynamic DataBinding jbenson001 ASP.NET 1.x and 2.0 Application Design 6 January 30th, 2004 03:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.