p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 3rd, 2007, 08:37 AM
Authorized User
 
Join Date: Aug 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bind a Label

I'm new in ASP. Can I bind a Label without be inside datalist, datagrid?. I wrote a function that retrieves "salesman name" from an access database but somehow retrieves "System.Data.OleDb.OleDbDataReader" and not the data.

<asp:Label id="lbl2" runat="server" text=<%# GetSalesman()%>/>

Can I do this without the use of datalist, repeater or datagrid.????

Thanksss.
C



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old January 3rd, 2007, 09:31 AM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

What does your function return?

-------------------------
I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old January 3rd, 2007, 04:32 PM
Authorized User
 
Join Date: Aug 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Public Function GetSalesman()

Dim myConn AS OleDbConnection
Dim myCommand As OleDbCommand
Dim myReader As OleDbDataReader
Dim query As String
'specify the data source
myConn = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/db/uoi.mdb"))
'define the command query
query = "SELECT Distinct Nro FROM Clients,Salesman WHERE Salesman.Username='" & Context.User.Identity.Name &"'"

'create a command object and set its
myCommand = new OleDbCommand ( query, myConn )

'open the connection and instantiate a datareader
myConn.Open ( )
myReader = myCommand.ExecuteReader ( )

return myReader
'close the reader and the connection
myReader.Close ( )
myConn.Close ( )

End Function

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old January 3rd, 2007, 05:13 PM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

First, your function is wrote incorrectly as these 2 lines

myReader.Close ( )
myConn.Close ( )

Will never get called. Move them above your return statement. If you want to bind the label to the result of that function, return a string. So something like:

Dim sString as string = myReader("column")

return sString

-------------------------
I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old January 9th, 2007, 12:31 PM
Authorized User
 
Join Date: Aug 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm still getting

Object reference not set to an instance of an object.


I move around those 2 lines you told me and add the string variable.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old January 9th, 2007, 12:36 PM
Authorized User
 
Join Date: Aug 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can i bind a label without being in a datagrid, datalist or repeater

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old January 9th, 2007, 01:15 PM
Authorized User
 
Join Date: Aug 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now I'm getting

BC30311: Value of type 'System.Data.OleDb.OleDbDataReader' cannot be converted to 'String'.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old January 9th, 2007, 02:21 PM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

Here is the problem: a datareader only contains data while you have a connection open to the database so returning a datareader from a function does you no good at all. You either A) have to return a datatable/set or B) Return a string value from your query. You will NOT be able to access any data outside of the above function using a datareader.

-------------------------
I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old January 10th, 2007, 09:27 AM
Authorized User
 
Join Date: Aug 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I create a function with a dataset but i'm getting Compiler Error Message: BC30408: Method 'Public Function GetSalesman(sender As Object, e As System.EventArgs) As Object' does not have the same signature as delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'.
--------------------------------------
Should i call the method as
Option1)
<asp:Label id="lbl2" runat="server" Text=<%#"GetSalesman"%>
or
Option2)
<asp:Label id="lbl2" runat="server" OnInit="GetVendedor">
If i do as option2 I get the above compiler error.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old January 10th, 2007, 09:36 AM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

Whats wrong with just doing:

Private Sub Page_Load(ByVal sender as Object, ByVal e as EventArgs)
If not Page.IsPostBack
     lbl2.Text = GetSalesman()
End If
End Sub

-------------------------
I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Bind Data in DataGrid akumarp2p C# 2005 2 December 30th, 2006 12:11 PM
Grid Bind msbsam ASP.NET 2.0 Basics 1 December 19th, 2006 07:03 AM
Bind Data to a Single Label Control: Possible? jumpseatnews ASP.NET 2.0 Basics 1 April 7th, 2006 12:12 AM
how to bind a data() lsxx Classic ASP Components 4 April 20th, 2005 03:35 AM
bind variable htummala Oracle 1 February 15th, 2005 05:32 AM



All times are GMT -4. The time now is 05:01 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc