Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 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 August 16th, 2004, 11:01 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default How I Can Use DataRows Collection

Hi Every one
I Have A problem with fetching a single column using DataRows Collection Using This code ANY One To Me Where I Maybe do mistake.
another thing that i must mentioned that i havent any problem with dispalying data in dataGrid by Bind Data To But I like only One Column or not all of columns of a table and other thing is that i like apply my own formatting when i displaying any data in my pages.

Code:
string strSql="select count_tall from counters;";
string strConnection="Data Source=mzz;Initial Catalog=members;Integrated Security=SSPI;" ;
            catalog=members;server=mzz;";
data_src.Text=strConnection;
 SqlDataReader objreader=null;
SqlConnection objSqlConnection=new SqlConnection(strConnection);
SqlCommand objcommand=new SqlCommand(strSql,objSqlConnection);

   try
    {
               objSqlConnection.Open();
                /*   */
                DataTable objDataTable;
                DataSet objDataSet=new DataSet();
                SqlDataAdapter objDataAdapter=new SqlDataAdapter(strSql,objSqlConnection);
  objDataAdapter.Fill(objDataSet,"counters");
  objDataTable=objDataSet.Tables["counters"];
        
Quote:
quote:string count=(string)objDataTable.Rows[0]["count_tall"];
Quote:
Response.Write(count);
When I Use The Quoted Section of code the page runs withut any error but dont dispaly any results in page .
ThanX In Advance.
YoOrD.
__________________
       YoOrD .
Beauty is not on the face
Beauty is on the heart
~~<<Ghibran Khalil>>~~
 
Old August 16th, 2004, 11:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

WHat are you doing with this:

objDataTable.Rows[0]["count_tall"];

I don't see what you do with this at all... try:

objDataTable=objDataSet.Tables["counters"];
dg1.DataSource=objDataTable.DefaultView;
dg1.DataBind();

Try using a data list instead, if you only want one field. That may suit your needs.

Brian
 
Old August 16th, 2004, 11:48 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

ThanX For Your Reply
i like to extract custom column of named row and display it in a table or in a <div>.
ThanX In Advance.
YoOrD.

 
Old August 16th, 2004, 12:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

If you want to display it in a div (which would be panel server-side control), you can do:

'strValue is the value you want to enter in the panel;
'Add & "<br>" to add a new line at the end of the value
Panel1.Control.Add(New LiteralControl(strValue))

Brian
 
Old August 16th, 2004, 12:11 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

is'nt there a simple way like what we use in ASP .
other things r u think my code havent any other problem ?
another thing in which chapter of Beginning asp.net book i can find this type of control and if u know online tutorials that help me.
Thanx In Advance.
YoOrD.
 
Old August 16th, 2004, 02:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You can find the panel control in the MSDN. adding a literalcontrol class to a panel isn't that bad compared to ASP... ASP.NET goes above and beyond, and so you may have a minor inconvenience but more functionality.

Do you only want to get one row of data from a query, or more than one row?

Brian
 
Old August 16th, 2004, 02:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I just thought of it... if you want to get a single value, you should try using ExecuteScalar, instead of passing it back to a datatable. This method returns a single scalar value from a proc.

Brian
 
Old August 16th, 2004, 03:21 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

no it is maybe more than one columns or some times maybe only one but
i was see in some texts like Beginning Asp.net using c# i read this text that it is easy to use such a syntax that in chap 13 page[503] manipulating data source i can see this:
  objTable=objDataSet.Tables["Employees"];
strFirstName=objTable.Rows[0]["FirstName"];
strFirstName is a string and we can write it as output is it wrong?

Thanx For Your Replies.
YoOrD.

 
Old August 17th, 2004, 08:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You can do Response.Write(strFirstName), but that is the non-preferred way of doing things. You can find discussion on other threads about this.

If it could be more than one, why grab each value, why not bind it to a datalist or repeater control? That would be easier than passing it to a variable and writing the variable?

What exactly do you want to do?

Brian
 
Old August 18th, 2004, 12:23 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks To You And Every One
Imust Clerify some thing about this issue that i like to use this in a page That must dispalys information about some one that are registered in a list or have a memberance in a site .
and i must show them thier information(personal informations like first,last ,email add,...) and give them to editing thier personal informations.
there some aspect about this topic that i must dispaly a selection information and not all information about a person and and he can view and changes other if it needed for them it is all of story about this topic i think i must clerify to you.
now if you and others have any good opinion that can help please replies me .
Thanks In Advance.
YoOrD.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Can anybody help? Collection in C# naveenj .NET Framework 2.0 4 July 15th, 2007 09:34 PM
Collection in C# ? dedex C# 1 January 14th, 2005 04:51 PM
COM Collection ben0027 Visual C++ 0 May 1st, 2004 05:19 AM
Help collection gone MikeB VS.NET 2002/2003 2 June 12th, 2003 02:33 AM





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