Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 October 21st, 2004, 01:53 AM
Authorized User
 
Join Date: Jan 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default posting single sql query result to label

im searching for a single row result with 3 columns all of which i want to paste into a single asp:label.

is it better to get the data using datareader or dataset?

if datareader howto access all datareader items using
 For Each Item In

do help..


ps: is it possible to share/inherit the classes between different codebehind files say between common.vb & finance.vb

 
Old October 21st, 2004, 10:26 AM
Authorized User
 
Join Date: Jun 2004
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to hlchuah77
Default

Why you want to "paste" the search result to label control? Isn't it good to display the result using DataGrid control?

DataReader is the faster technique for reading data from database if compared to other method. Anyhow, I still do not have any idea yet in fetching data using DataReader, I use only DataAdapter together with DataSet.

The following is the sample coding that I have tried, you can use it as alternative way for this moment until there is the one who may advice you on how to access all the DataReader item using foreach loop. Here is the coding:

void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        string conn = "server=(local);database=Northwind;" +
                        "integrated security=true;";

        string queryString = "select * from Products";

        SqlConnection DbConn = new SqlConnection(conn);

        SqlCommand DbComm = new SqlCommand(queryString, DbConn);

        SqlDataAdapter Adapter = new SqlDataAdapter();

        Adapter.SelectCommand = DbComm;

        DataSet dataSet = new DataSet();

        Adapter.Fill(dataSet, "Products");

        for (int i = 0; i < 5; i++)
        {
            if (i < 4)
                Label1.Text += dataSet.Tables["Products"].Rows[0][i].ToString() + "," + " ";
            else
                Label1.Text += dataSet.Tables["Products"].Rows[0][i].ToString();
        }

        Label1.DataBind();
  }
}


 
Old October 23rd, 2004, 12:29 AM
Authorized User
 
Join Date: Jan 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by hlchuah77
 Why you want to "paste" the search result to label control? Isn't it good to display the result using DataGrid control?
the point is i only have one result say like the shipping address field of a company .. & i wanted it when i create a new purchase order.. in such a situation whats the logic in using a datagrid?

the following code is ok if i know the exact no. of fields in the sql return .. but in my case i made a function to which i give the sql statement and it returns the single result as string . . since i dont have a choice for the time being im using ur code ... thanx hlchuah77

ps:i use vb.net






Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing an SQL query and using it's result Andrew.Berry ASP.NET 2.0 Professional 5 April 14th, 2008 08:25 AM
check the result of sql query Abhinav_jain_mca ADO.NET 2 August 11th, 2004 11:58 AM
xml result set truncated in sql query analyzer xologist SQL Server 2000 2 March 22nd, 2004 05:23 PM
Paging of Sql Query Result. SubodhKumar SQL Language 4 December 13th, 2003 06:58 PM
Setting a Variable = Result of a SQL Query PeteS VB Databases Basics 1 June 20th, 2003 08:14 AM





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