Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 March 29th, 2007, 11:46 PM
Authorized User
 
Join Date: Feb 2007
Location: Bend, Oregon, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting data from a data reader

ok, here is my code:

Dim AccountParam As Data.SqlClient.SqlParameter
        Dim Resource As String
        Dim MyConnection As Data.SqlClient.SqlConnection
        Dim InitialCommand As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand( _
        "Select (FirstName + ' ' + LastName) as Name, PkProfessional From Professional Where WindowsAccount=@Account;")
        Dim MyReader As Data.SqlClient.SqlDataReader
        MyConnection = New Data.SqlClient.SqlConnection
        MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("RASConnect ionString").ConnectionString
        InitialCommand.Connection = MyConnection
        InitialCommand.CommandType = Data.CommandType.Text

        AccountParam = New Data.SqlClient.SqlParameter
        AccountParam.ParameterName = "@Account"
        AccountParam.SqlDbType = Data.SqlDbType.VarChar
        AccountParam.Size = 15
        AccountParam.Direction = Data.ParameterDirection.Input
        AccountParam.Value = DropDownList1.Text
        InitialCommand.Parameters.Add(AccountParam)

        InitialCommand.Connection.Open()
        MyReader = InitialCommand.ExecuteReader

        'how do I get the data that was returned and put it into my Resource variable so that I can use it?

        InitialCommand.Dispose()
        MyConnection.Dispose()


The reader works fine but I have no idea how to grab the data that I queried for and put it into a variable so I can assign to a label or whatever.



 
Old March 30th, 2007, 06:53 AM
Authorized User
 
Join Date: Dec 2006
Location: , , India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sunnys Send a message via Yahoo to Sunnys
Default

just use
while(MyReader.read())
{
 lblName.text=MyReader.GetString(0);
}
 this will do

 
Old March 30th, 2007, 06:54 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Start with something like this:

If MyReader.Read() Then
   Resource = MyReader("Name").ToString()
   'do something with resource
   Resource = MyReader("PkProfessional").ToString()
   'do something with resource
End If

Reader.Read() will advance you to each row of the reader results, and return False when there's no more rows.

-Peter
 
Old March 30th, 2007, 09:16 AM
Authorized User
 
Join Date: Feb 2007
Location: Bend, Oregon, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

fantastic.

Thanks for the help





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter6.1.3 :Data Reader Source johe BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 November 28th, 2008 04:35 AM
Data reader checking.... janees ASP.NET 1.0 and 1.1 Professional 1 March 11th, 2007 06:09 AM
oracle data reader silvia C# 10 February 2nd, 2006 07:30 AM
Fill data set from data reader sunil menghani ADO.NET 3 March 29th, 2005 07:08 AM





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