Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



Reply
getting label.text from a database
Old 07-17-2006, 02:20 PM getting label.text from a database
Experienced Talker

Posts: 48
Trades: 0
hi guys,

once again, greetings......

i am using VS2005 - Visual Studio 2005.



ok, what i would like to do is display data from a database in a label.


i have a db called database.mdf (the default one in VS).
i have a table called CMS,
which has two fields, one called id and one called text.
i want to hard code it to say get me text from CMS where ID = 1 (or whatever), and make it the text of label1.

can i bind a label like this to a database???????

i hope to goodness i can!!!!

all help is very appreciated!!!!!


__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)
paulwebmaster is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-18-2006, 06:32 AM Re: getting label.text from a database
King Spam Talker

Posts: 1,186
Location: Manchester, UK
Trades: 0
I don't think you can bind a label to a datasource. I think you would have to return a variable from a sql statement and then update label.text with it in your code. There's an article here that explains how to retrieve scalar data from a stored procedure, maybe you'll find that useful?
gringo is offline
Reply With Quote
View Public Profile Visit gringo's homepage!
 
Old 07-18-2006, 01:39 PM Re: getting label.text from a database
Experienced Talker

Posts: 48
Trades: 0
ok cool, thats what i meant.
great minds think a like.

do you know any good tutorials that would show me how to do that.

i have set up my sqldatasource and it is getting what i want.
now unsure of how to set the result as a variable.
after that i suppose i can just say label1.text = variablename


im a bit new to VS2005.

i would usually declare as a DIM in web matrix but am unsure of how to do this in vs2005.....
__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)

Last edited by paulwebmaster; 07-18-2006 at 01:41 PM..
paulwebmaster is offline
Reply With Quote
View Public Profile
 
Old 07-18-2006, 03:29 PM Re: getting label.text from a database
King Spam Talker

Posts: 1,186
Location: Manchester, UK
Trades: 0
Did you have a look at the link I gave? 4guysfromrolla has some good articles so it might be worth your while having a look around
gringo is offline
Reply With Quote
View Public Profile Visit gringo's homepage!
 
Old 07-18-2006, 05:52 PM Re: getting label.text from a database
boomers's Avatar
Extreme Talker

Posts: 229
Trades: 1
Im not totally sure what you mean but ima give it a try... here's what I think you want to do.

Overview: You have a record (which is plain text & within a column called 'text') within a database (called CMS) & you want that record to be displayed via a label. This example is an example of retrieving from an SQL DB.

Code:
Dim SQLCommand As New SqlCommand("SELECT text FROM CMS WHERE ID ='1'", **insert connection name here**)

**insert connection name here**.Open()
Dim myDataReader As SqlDataReader = SQLCommand.ExecuteReader()
If myDataReader.HasRows Then
Me.Label1.Text =  myDataReader("text")
else
Me.Label1.Text =  "No Records"
end if
**insert connection name here**.Close()
I hope this makes sence to you and also that Ive understood your request properly
boomers is offline
Reply With Quote
View Public Profile
 
Old 07-25-2006, 12:47 PM Re: getting label.text from a database
Experienced Talker

Posts: 48
Trades: 0
hi guys.

for any one thats intersted i mananged to bind to a text box.

what i did was set up a SQLDATASOURSE then put a FORMVIEW on the page.

if u select the primary key as part of your SQLDATASOURSE then you can tick the "allow update, edit, delete" check box in the data source wizard.

once this is set up, and you have bound the label (in itemtemplate) and textbox(in edit template) to the text field in your database you can edit the text on the page.

i have a script on the page that triggers all textboxs to start up my TINYMCE wissywig. this allows me to add formating, hyperlinks, emoticons, fonts, whatever....

basically i now have a pretty cool CMS for my site. meaing i dont have to do any more content work!!!!! hurray, the users can change the content now. it so simple!!!!

if any one wants further tips on setting this up ill be happy to help VS2005 users.
__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)

Last edited by paulwebmaster; 07-25-2006 at 12:48 PM..
paulwebmaster is offline
Reply With Quote
View Public Profile
 
Old 08-24-2006, 08:17 AM Re: getting label.text from a database
saadatshah's Avatar
Extreme Talker

Posts: 215
Name: Syed Saadat Ali
Location: Lahore, Pakistan
Trades: 0
__________________
- -- --- ---- ----- ------ ------- ---------------
If you have knowledge, let others light their candles in it.
saadatshah is offline
Reply With Quote
View Public Profile Visit saadatshah's homepage!
 
Reply     « Reply to getting label.text from a database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41980 seconds with 12 queries