Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Easiest way to retreive single value


Easiest way to retreive single value

Reply
  #1 (permalink)  
Old 07-26-04, 03:15 PM
andreasberglind andreasberglind is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Sweden
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Easiest way to retreive single value

Could someone tell me how to retreive a single row from a SQL database and display it on a .aspx page? This component/function is only going to display a name, so itīs probably very simple, i just need to find out wich way to go.

Could someone point me in the right direction?

Thanks!
Reply With Quote
  #2 (permalink)  
Old 10-20-04, 12:07 AM
thuenb thuenb is offline
Newbie Coder
 
Join Date: Oct 2004
Location: MI
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Use Scalar

Basically you create a Sql statement that gives you only the column of data that you want... Without coding the whole thing... Something like this..

Code:
imports system.data
imports system.data.sqlclient


Dim cnn As New SqlConnection("User Id=MyUserID;Password=MyPassword;Initial Catalog=DBName;Server=255.255.255.255")

'Modify the SQL string to match your criteria
Dim cmd As New SqlCommand("Select Name From TableName where Id = 0", cnn) 

label.Text = cmd.ExecuteScalar

'Don't forget to clean up your connection and cmd objects by setting them to nothing
hope this helps....
__________________
Best Regards,
Brian Thuen
http://www.AdvisedSolutions.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to return a single key from a hash chaos7 Perl 2 06-04-04 12:20 PM
using single quote nuchy Visual Basic 5 12-07-03 04:32 PM
running dll script using single http call? Bahlool HTML/XHTML/XML 0 10-11-03 03:16 AM
Retreive info from Database? EST PHP 1 08-15-03 03:43 AM
Flatfile single Forum with Perl Gaz General HotScripts Site Discussion 1 08-07-03 04:37 AM


All times are GMT -5. The time now is 12:54 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.