Wrox Programmer Forums
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET 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 December 22nd, 2005, 12:10 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If you have several queries that get single values, why not use the even simpler: command.ExecuteScalar(). That will return a single value and you don't need to .Read() thru a reader at all. Then just assign the value to your textbox.

-Peter
 
Old December 23rd, 2005, 06:11 AM
Authorized User
 
Join Date: Dec 2005
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry to sound dumb here, but you wouldnt happen to have a code exmaple??

 
Old December 23rd, 2005, 10:29 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Dim objCmd As SqlCommand
Dim strValue As String

objCmd = New SqlCommand("SELECT field FROM table", objMyConnection)
objCmd.Connection.Open()
strValue = objCmd.ExecuteScalar()
objCmd.Connection.Close()


-Peter
 
Old December 23rd, 2005, 10:29 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

http://msdn.microsoft.com/library/en...calartopic.asp









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