VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,412 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,585 people online right now. Registration is fast and FREE... Join Now!




Setting hyperlink text from database at runtime

 

Setting hyperlink text from database at runtime

oyster_catcher86

30 Jun, 2009 - 02:45 AM
Post #1

New D.I.C Head
*

Joined: 30 Jun, 2009
Posts: 3

Hello,i have a problem in setting hyperlink text property from database at runtime....Iam struggling to connect the database values to dynamic hyperlinks....could you kindly help me with this.....
Thank you

This post has been edited by oyster_catcher86: 30 Jun, 2009 - 02:46 AM

User is offlineProfile CardPM
+Quote Post


CamoDeveloper

RE: Setting Hyperlink Text From Database At Runtime

30 Jun, 2009 - 11:57 AM
Post #2

D.I.C Head
Group Icon

Joined: 12 Jun, 2009
Posts: 204



Thanked: 12 times
Dream Kudos: 200
My Contributions
What is the code you're using?

~Camo
User is offlineProfile CardPM
+Quote Post

modi123_1

RE: Setting Hyperlink Text From Database At Runtime

30 Jun, 2009 - 12:32 PM
Post #3

Suiter #2
Group Icon

Joined: 12 Jun, 2008
Posts: 1,760



Thanked: 72 times
Dream Kudos: 150
My Contributions
It should be simple. Form loads. You go to the database to get the string URL. When the data comes back from the database set the URL property of the hyper link label to the string you came back with.
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Setting Hyperlink Text From Database At Runtime

30 Jun, 2009 - 01:28 PM
Post #4

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: code.gif

Thanks.
User is offlineProfile CardPM
+Quote Post

oyster_catcher86

RE: Setting Hyperlink Text From Database At Runtime

30 Jun, 2009 - 10:59 PM
Post #5

New D.I.C Head
*

Joined: 30 Jun, 2009
Posts: 3

I have posted the code below
CODE

Public Sub linkbutton()
        Dim dylb As New LinkButton()

        con.Open()
        cmd.Connection = con
        cmd.CommandText = "select series from list_of_series where season=1880"
        cmd.ExecuteNonQuery()
                    'I obtain the error here when using data adapter or data reader to fetch the single record for each linkbutton
        'In linkbutton text it displays as system.data.sqlclient....
        'How to fetch records one by one and assign to link buttons text....
                    dylb.Text = ""

        dylb.ID = "dylb"
      
        AddHandler dylb.Click, AddressOf dylb_Click

        Me.form1.Controls.Add(dylb)

        dylb.PostBackUrl = "http://localhost:20277/sample2/flowers.aspx";

        con.Close()

    End Sub


This post has been edited by oyster_catcher86: 30 Jun, 2009 - 11:02 PM
User is offlineProfile CardPM
+Quote Post

modi123_1

RE: Setting Hyperlink Text From Database At Runtime

1 Jul, 2009 - 07:37 AM
Post #6

Suiter #2
Group Icon

Joined: 12 Jun, 2008
Posts: 1,760



Thanked: 72 times
Dream Kudos: 150
My Contributions
If you want the data back you need to create a data reader and use the 'execute reader'. There is a tutorial here or MSDN can help you.

What sort of column data type is "season"? If that's a varchar you will need to wrap '1880' in tick marks to have it treated as a string of VARCHARs
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Setting Hyperlink Text From Database At Runtime

1 Jul, 2009 - 08:18 AM
Post #7

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
I would change this

CODE

cmd.ExecuteNonQuery()



To something like this (using ExecuteScalar as using a SqlDataReader is a bit overkill for one item returned)

CODE

Dim url As String = CType(cmd.ExecuteScalar(), String)



Then the variable url will hold the data from the table
User is offlineProfile CardPM
+Quote Post

oyster_catcher86

RE: Setting Hyperlink Text From Database At Runtime

1 Jul, 2009 - 10:03 PM
Post #8

New D.I.C Head
*

Joined: 30 Jun, 2009
Posts: 3

Actually this project is about creating a websit about cricket statistics and the season here is refered as year which the match was played.In the home page i have the link test matches when it is clicked it navigates to another page which contains dynamic linkbuttons of list of matches and this list of matches is pulled form the database,and each linkbutton should display each match name from database....Iam trying first for a single link button here.I tried with datareader but it posts some error as datareader has no constructors

Thank you for your reply

This post has been edited by oyster_catcher86: 1 Jul, 2009 - 10:21 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:10PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month